June 2017
Intermediate to advanced
400 pages
8h 44m
English
Implementing an Observer is a bit verbose and cumbersome. Thankfully, the subscribe() method is overloaded to accept lambda arguments for our three events. This is likely what we will want to use for most cases, and we can specify three lambda parameters separated by commas: the onNext lambda, the onError lambda, and the onComplete lambda. For our previous example, we can consolidate our three method implementations using these three lambdas:
Consumer<Integer> onNext = i -> System.out.println("RECEIVED: " + i); Action onComplete = () -> System.out.println("Done!"); Consumer<Throwable> onError = Throwable::printStackTrace;
We can pass these three lambdas as arguments to the subscribe() method, and it will ...
Read now
Unlock full access