I am new in RxJava and trying to understand it. I have the following source:
Observable<Employee> obs = Observable.just(
new Employee(101, "Jim", 68_000, 4.2),
new Employee(123, "Bill", 194_000, 6.7));
obs.groupBy(e -> e.getRating())
.flatMapSingle(e -> e.toMultimap(key -> e.getKey(), emp -> emp.getName()))
.subscribe(System.out::println);
This approach prints the keys and the associated value.
If I do:
obs.groupBy(e -> e.getRating())
.flatMapSingle(e -> e.toList())
.subscribe(System.out::println);
It seems to print the list of values associated with the key.
But how does flatMapSingle
exactly work? What is the difference with flatMap
?