flatmap

What is the difference between concatMap and flatMap in RxJava

允我心安 提交于 2019-11-26 19:49:11
问题 It seems that these 2 functions are pretty similar. They have same signature (accepting rx.functions.Func1<? super T, ? extends Observable<? extends R>> func ), and their marble diagrams look exactly same. Can't paste the pics here, but here's one for concatMap, and here's one for flatMap. There seems to be some subtle difference in the description of resulting Observable , where one produced by concatMap contains items that result from concatinating resulting Observables, and the one

When do you use map vs flatMap in RxJava?

牧云@^-^@ 提交于 2019-11-26 18:09:42
When do you use map vs flatMap in RxJava? Say for example, we want to map Files containing JSON into Strings that contain the JSON-- Using map, we have to deal with the Exception somehow. But how?: Observable.from(jsonFile).map(new Func1<File, String>() { @Override public String call(File file) { try { return new Gson().toJson(new FileReader(file), Object.class); } catch (FileNotFoundException e) { // So Exception. What to do ? } return null; // Not good :( } }); Using flatMap, it's much more verbose, but we can forward the problem down the chain of Observables and handle the error if we

Java 8 Streams FlatMap method example

徘徊边缘 提交于 2019-11-26 07:59:41
问题 I have been checking the upcoming Java update , namely: Java 8 or JDK 8 . Yes, I am impatient, there\'s a lot of new stuff, but, there is something I don\'t understand, some simple code: final Stream<Integer>stream = Stream.of(1,2,3,4,5,6,7,8,9,10); stream.flatMap(); the javadocs are public <R> Stream<R> flatMap(Function<? super T,? extends Stream<? extends R>> mapper) Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream

When do you use map vs flatMap in RxJava?

拥有回忆 提交于 2019-11-26 06:12:01
问题 When do you use map vs flatMap in RxJava? Say for example, we want to map Files containing JSON into Strings that contain the JSON-- Using map, we have to deal with the Exception somehow. But how?: Observable.from(jsonFile).map(new Func1<File, String>() { @Override public String call(File file) { try { return new Gson().toJson(new FileReader(file), Object.class); } catch (FileNotFoundException e) { // So Exception. What to do ? } return null; // Not good :( } }); Using flatMap, it\'s much