Skip to content

cyclops streams ReactiveSeq for comprehension operators (forEach2, forEach3)

johnmcclean-aol edited this page Nov 21, 2016 · 1 revision

Cyclops has merged with simple-react. Please update your bookmarks (stars :) ) to https://github.com/aol/cyclops-react

screen shot 2016-02-22 at 8 44 42 pm

for-comprehensions within a Stream

ReactiveSeq has a number of operators that make it easy to iterate simultanously over multiple Streams generating a new Stream in the process - these are the various overloading versions of forEach2 & forEach3.

Examples

Loop over two Streams (one containing 3 values another 10 to create a new Stream of 30 values)

ReactiveSeq.of(1,2,3)
                 .forEach2(a->IntStream.range(0,10), 
                         a->b-> a+b)
                 .toList()

//List[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 
                         9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)]

Also With the ability to filter

ReactiveSeq.of(2,3)
		         .forEach3(a->IntStream.range(6,9),
		        		   a->b->IntStream.range(100,105),
		        		   a->b->c -> a==3,
		        		   a->b->c-> a+b+c)

//List[109, 110, 111, 112, 113, 110, 111, 112, 113, 114, 111, 112, 113, 114, 115]

See also

Clone this wiki locally