package com.mikeart.rxartistlist.data.repository;

import com.mikeart.rxartistlist.data.entity.mapper.ArtistEntityDataMapper;
import com.mikeart.rxartistlist.data.repository.datasource.ArtistDataStore;
import com.mikeart.rxartistlist.data.repository.datasource.ArtistDataStoreFactory;
import com.mikeart.rxartistlist.domain.Artist;
import com.mikeart.rxartistlist.domain.repository.ArtistRepository;

import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Observable;

/**
 * {@link ArtistRepository} for retrieving artist data.
 */
@Singleton
public class ArtistDataRepository implements ArtistRepository {

  private final ArtistDataStoreFactory artistDataStoreFactory;
  private final ArtistEntityDataMapper artistEntityDataMapper;

  /**
   * Constructs a {@link ArtistRepository}.
   *
   * @param dataStoreFactory A factory to construct different data source implementations.
   * @param artistEntityDataMapper {@link ArtistEntityDataMapper}.
   */
  @Inject
  public ArtistDataRepository(ArtistDataStoreFactory dataStoreFactory,
                              ArtistEntityDataMapper artistEntityDataMapper) {
    this.artistDataStoreFactory = dataStoreFactory;
    this.artistEntityDataMapper = artistEntityDataMapper;
  }

  @Override public Observable<List<Artist>> artists() {
    final ArtistDataStore artistDataStore = this.artistDataStoreFactory.createList();
    return artistDataStore.artistEntityList().map(this.artistEntityDataMapper::transform);
  }

  @Override public Observable<Artist> artist(int artistId) {
    return artists().flatMapIterable(ArtistEntity -> ArtistEntity).filter(UserEntity -> UserEntity.getArtistId() == artistId);
  }
}

@@ -1555,24 +1555,176 @@
 artistId) %7B%0A
+    // converts Observabe%3CList%3E in Observable that emits every particular item from list%0A    // obtains particular Artist by ID from the new Observable%0A
     return a
@@ -1781,16 +1781,29 @@
 ity)
+%0A            
 .filter(
 User
@@ -1798,20 +1798,22 @@
 .filter(
-User
+Artist
 Entity -
@@ -1818,12 +1818,14 @@
  -%3E 
-User
+Artist
 Enti

comment on rx filter was added