Reputation: 16587
I want to filter List<Object>
based on query from user and then return List<Object>
to him/her.I found out how to filter items But the problem is I don't know how return List<Object>
. I also see some approach which iterate and call flatMap
each time But I didn't think it's an elegant way.
This is my last attempt:
Observable.from(my_list_of_object)
.debounce(500, TimeUnit.MILLISECONDS)
.filter(new Func1<MyObject, Boolean>() {
@Override
public Boolean call(MyObject o) {
return o.getName().contains(query); //filtering
}
})
.observeOn(Schedulers.computation())
//problem is here and I dont know how
//to convert filtered Item to list
Upvotes: 5
Views: 13167
Reputation: 2390
Just use toList()
operator.
Check the documentation.
Observable.from(my_list_of_object)
.debounce(500, TimeUnit.MILLISECONDS)
.filter(new Func1<MyObject, Boolean>() {
@Override
public Boolean call(MyObject o) {
return o.getName().contains(query); //filtering
}
})
.toList()
.observeOn(Schedulers.computation())
You can find more extensive list of aggregate operators here.
Upvotes: 13