Skip to content

Instantly share code, notes, and snippets.

@danielkec
Created March 20, 2020 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkec/d09713b52da2ede80c418472a494033a to your computer and use it in GitHub Desktop.
Save danielkec/d09713b52da2ede80c418472a494033a to your computer and use it in GitHub Desktop.
AtomicInteger sum = new AtomicInteger();
Flowable<Integer> flowable = Flowable.just("1", "2", "3", "4", "5")
.map(Integer::parseInt);
ReactiveStreams.fromPublisher(flowable)
.limit(3)
.forEach(sum::addAndGet)
.run()
.whenComplete((r, t) -> System.out.println("Sum: " + sum.get()));
> Sum: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment