RxScala "zip" multiple Observables

RxScala "zip" multiple Observables

rxscala maven
rxscala vs akka
rxjava
rxjava java 7
io reactivex rxjava3 rxjava
android reactivex
rx php
netflix rxjava github

In RxScala how to "zip" more than 2 Observables?

val ob1: Observable[Int] = Observable.from(Future(10))
val ob2: Observable[Int] = Observable.from(Future(20))
val ob3: Observable[Int] = Observable.from(Future(30))

"zip" works perfect with 2 Observables

val obComb: Observable[(Int, Int, Int)] = ob1 zip ob2

How do we "zip" more than 2 Observables?


You can use zipWith which lets you provide your "zipping" function.

val obComb = ob1
  .zipWith(ob2)({ case (x1, x2) => (x1, x2) })
  .zipWith(ob3)({ case ((x1, x2), x3) => (x1, x2, x3) })

ReactiveX/RxScala: RxScala – Reactive Extensions for , RxScala – Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences. Star 882. Watch  RxScala – Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences - ReactiveX/RxScala


If you have more than 3 observables, you can also use:

val allObs = Observable.from(List(ob1, ob2, ob3))
val zipObs = Observable.zip(allObs)

If you don't like the static way, you can also try:

val zipObs = ob1 zip ob2 zip ob3 map {
   case ((a, b), c) => (a, b, c)
}

Releases · ReactiveX/RxScala · GitHub, RxScala – Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences - ReactiveX/RxScala. RxScala: Reactive Extensions for Scala This is a Scala adapter to RxJava.


Since zipping more than two Observables can't be defined "nicely" as an instance method, it's defined as a "static" method in the companion object. That is, to zip three Observables, you write

val obComb = Observable.zip(ob1, ob2, ob3)

Intro to RxScala, Intro to RxScala. beachape.com/rx-scala-intro. Overview. Focus on usage. What is an asynchronous stream? Where are asynchronous streams in a given app? Version Scala Repository Usages Date; 0.27.x. 0.27.0: 2.13 2.12 2.11 2.10: Central: 0 Dec, 2019


Reactive Programing and RxScala, In this book, we will use RxScala, which is the Scala implementation of the Reactive Streams. The following table shows the main class/concepts you need to know  An asynchronous stream is a source of objects, but the objects are produced at different points in time. Where are asynchronous streams in a given app? Technically, anywhere you want to handle something asynchronously. This means that you can use it to represent a single asynchronous result, such as a Future.


Introduction · (ABANDONED) Scala meets Rx with RxScala, Rx is single-threaded by default; events are most certainly single threaded and synchronous; Rx is just a way of chaining callbacks together for a given  REScala is a library for functional reactive programming on the JVM and the Web. It provides a rich API for event stream transformations and signal composition with managed consistent up-to-date state and minimal syntactic overhead.


rxscala, RxScala – Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences. GitHub. scala 2.13. Spaceship Reactive - A port of Spaceship Reactive found in Sergi Mansillas awesome book Reactive Programming with RxJS. Code can be found here. RxScala.js as a state store - A basic example on how to write a simple state store with RxScala.js. (Find the working example here)