June 2018
Intermediate to advanced
310 pages
6h 32m
English
Having those values captured in a closure may seem a bit ugly. There's a more functional alternative, but it's quite hard to grasp. Generate can receive two functions instead of one:
<T, S> Flowable<T> generate(Callable<S> initialState, BiFunction<S, Emitter<T>, S> generator)
Well, that's a mouthful. Let's try to understand what's going on there.
The first initial state is () -> State. In our case, the state can be represented as follows:
data class State(val count: Int, val startTime: Long)
We don't pass an instance of CountDownLatch to our function for the sake of simplicity. You'll soon understand why.
So, our first argument is the () -> State function, which has no parameters and returns a State. Now, the second argument ...
Read now
Unlock full access