Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an observable from Hashmap?

Based on ReactiveX documentation

the from operator can convert a Future, an Iterable, or an Array. In the case of an Iterable or an Array, the resulting Observable will emit each item contained in the Iterable or Array.

we can have an observable from an Array or List and observable emits the items in the list.

I have a HashMap<String,Item> and i want to iterate through the items just like making an observable with Observable.from(List<Item>).

In other words, i want the observable to emit HashMap Items.

Is there a solution to do this?

like image 206
Morteza Rastgoo Avatar asked Aug 12 '15 09:08

Morteza Rastgoo


1 Answers

You can make the map entries into an Observable like this:

Observable<Entry<String, Item>> entries = 
    Observable.from(map.entrySet());

If you just want the values from the map:

Observable<Item> items = Observable.from(map.values());
like image 161
Dave Moten Avatar answered Oct 31 '22 07:10

Dave Moten