If flatMapSingle () is used when connecting Flowable or Maybe to Single, NoSuchElementException may occur.
When connecting a Single to a stream where Complete may flow, if Complete actually flows, it cannot be processed by Single and an exception will fly, and the application will die as it is. RxJava does a good job of connecting Flowable to Single normally. In the first place, I can't connect Single to Completable. However, flatMapSingle () will connect without any problem, so you need to use flatMapSingleElement () instead. There are no compilation errors, no error logs, no IDE warnings, but we have to be aware that we're doing something weird.
If you write a process that connects asynchronous processes with a flatMap and connects them, you will feel that Rx is a monad of asynchronous processes, and there is a merit that you will feel that you fully understand the functional type. On the contrary, by using flatMap or andThen, I wonder if it will be possible to understand monads using that as a clue ...
Recommended Posts