aol / cyclops-integration

Home of the cyclops integration modules : support for Scala, Clojure, RxJava (1+2), Reactor, FunctionalJava, Guava, Dexx & Vavr
http://cyclops-react.io
MIT License
442 stars 51 forks source link

Make extracting native collection types from lazy / reactive Xtended Collections simple #269

Closed johnmcclean closed 7 years ago

johnmcclean commented 7 years ago

Example

API for pushing data asynchronously from a reactive-stream with non-blocking back pressure into a Scala Immutable List, using both cyclops-react and Reactor types.

1. cyclops-react types

LinkedListX<Integer> asyncScalaList = Spouts.reactive(Stream.of(1,2,3),Executors.newFixedThreadPool(1))
                                            .map(this::asyncProcessing)
                                            .to()
                                            .linkedListX(LAZY)
                                            .type(Scala.LIST)
                                            .filter(this::targetValues);

//some processing while asyncScalaList is asyncrhonously populated

//extract underlying Scala List for use (blocking operation)
List<Integer> scalaList = asyncScalaList.to(ScalaConverters.List);

2. Similar code mixing Reactor and Scala collections

Flux<Integer> flux = Flux.of(1,2,3)
                         .subscribeOn(Executors.newFixedThreadPool(1)))
                         .map(this::asyncProcessing);

LinkedListX<Integer> asyncScalaList = Spouts.from(flux)
                                            .to()
                                            .linkedListX(LAZY)
                                            .type(Scala.LIST)
                                            .filter(this::targetValues);

//some processing while asyncScalaList is asyncrhonously populated

//extract underlying Scala List for use (blocking operation)
List<Integer> scalaList = asyncScalaList.to(ScalaConverters.List);
johnmcclean commented 7 years ago

Released in MI2