Reputation: 2053
return repository.loadItems(id)
.take(1)
.flatMapIterable { item -> item }
.map { item -> item.clientId}
.toList()
.toFlowable()
.distinct();
fun loadItems(id: Int): Flowable<List<Item>> {
return dao.loadItems(id)
}
I fetch List map to List and want to filter and save only unique ones, while distinct() doesn't work it brings as much items as the initial list is
Upvotes: 1
Views: 226
Reputation: 70017
distinct
filters out duplicates that pass through it. Since you applied it at the wrong place, it only receives a List
object which by itself is distinct.
Apply distinct
before the toList
to get the unrolled List
get filtered before it gets aggregated into a new List
.
return repository.loadItems(id)
.take(1)
.flatMapIterable { item -> item }
.map { item -> item.clientId}
.distinct() // <------------------------------------------------------
.toList()
.toFlowable()
Upvotes: 3