Reactive Programming With Java 9 by Jog Tejaswini Mandar

Reactive Programming With Java 9 by Jog Tejaswini Mandar

Author:Jog, Tejaswini Mandar [Jog, Tejaswini Mandar]
Language: eng
Format: azw3
Tags: COM051000 - COMPUTERS / Programming / General, COM051280 - COMPUTERS / Programming Languages / Java
Publisher: Packt Publishing
Published: 2017-09-21T04:00:00+00:00


Using the sum() operator

The sum() operator emits the value that is the calculated sum of all the items emitted by any Observable. Let's calculate the sum of the items emitted by the range() operator as follows:

public static void main(String[] args) { MathFlowable.sumInt(Flowable.range(1, 10)).subscribe(new Subscriber<Integer>() { @Override public void onComplete() { // TODO Auto-generated method stub System.out.println("completed successfully"); } @Override public void onError(Throwable throwable) { // TODO Auto-generated method stub throwable.printStackTrace(); } @Override public void onNext(Integer value) { // TODO Auto-generated method stub System.out.println(value); } @Override public void onSubscribe(Subscription subscription) { // TODO Auto-generated method stub subscription.request(1); } }); }

The following marble diagram describes the sum() operator:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.