• Stars
    star
    885
  • Rank 49,432 (Top 2 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RxScala – Reactive Extensions for Scala – a library for composing asynchronous and event-based programs using observable sequences

RxScala: Reactive Extensions for Scala

This is a Scala adapter to RxJava.

End-of-Life (EOL) notice

This project is end of life and new releases will only contain bug-fixes and support for new Scala versions. For more information, see issue #244.

Alternatives to this library:

Usage

Example usage:

val o = Observable.interval(200 millis).take(5)
o.subscribe(n => println("n = " + n))
Observable.just(1, 2, 3, 4).reduce(_ + _)

For-comprehensions are also supported:

val first = Observable.just(10, 11, 12)
val second = Observable.just(10, 11, 12)
val booleans = for ((n1, n2) <- (first zip second)) yield (n1 == n2)

Further, this adaptor attempts to expose an API which is as Scala-idiomatic as possible. This means that certain methods have been renamed, their signature was changed, or static methods were changed to instance methods. Some examples:

 // instead of concat:
def ++[U >: T](that: Observable[U]): Observable[U]

// instance method instead of static:
def zip[U](that: Observable[U]): Observable[(T, U)] 

// the implicit evidence argument ensures that dematerialize can only be called on Observables of Notifications:
def dematerialize[U](implicit evidence: T <:< Notification[U]): Observable[U] 

// additional type parameter U with lower bound to get covariance right:
def onErrorResumeNext[U >: T](resumeFunction: Throwable => Observable[U]): Observable[U] 

// curried in Scala collections, so curry fold also here:
def fold[R](initialValue: R)(accumulator: (R, T) => R): Observable[R] 

// using Duration instead of (long timepan, TimeUnit duration):
def sample(duration: Duration): Observable[T] 

// called skip in Java, but drop in Scala
def drop(n: Int): Observable[T] 

// there's only mapWithIndex in Java, because Java doesn't have tuples:
def zipWithIndex: Observable[(T, Int)] 

// corresponds to Java's toList:
def toSeq: Observable[Seq[T]] 

// the implicit evidence argument ensures that switch can only be called on Observables of Observables:
def switch[U](implicit evidence: Observable[T] <:< Observable[Observable[U]]): Observable[U]

// Java's from becomes apply, and we use Scala Range
def apply(range: Range): Observable[Int]

// use Bottom type:
def never: Observable[Nothing] 

Also, the Scala Observable is fully covariant in its type parameter, whereas the Java Observable only achieves partial covariance due to limitations of Java's type system (or if you can fix this, your suggestions are very welcome).

For more examples, see RxScalaDemo.scala.

Scala code using Rx should only import members from rx.lang.scala and below.

Master Build Status

Communication

Versioning

RxScala version Compatible RxJava version
0.27.* 1.0.*
0.26.* 1.0.*
0.25.* 1.0.*
0.24.* 1.0.*
0.23.*[1] 1.0.*
0.22.0 1.0.0-rc.5
0.21.1 1.0.0-rc.3
0.X.Y (X < 21)[2] 0.X.Y

[1] You can use any release of RxScala 0.23 with any release of RxJava 1.0. E.g, use RxScala 0.23.0 with RxJava 1.0.1
[2] You should use the same version of RxScala with RxJava. E.g, use RxScala 0.20.1 with RxJava 0.20.1

If you are using APIs labeled with Experimental/Beta, or ExperimentalAPIs (deprecated since 0.25.0), which uses RxJava Beta/Experimental APIs, you should use the corresponding version of RxJava as the following table:

RxScala version Compatible RxJava version
0.26.5 - 0.27.0 1.2.4+
0.26.4 1.2.2+
0.26.3 1.2.0+
0.26.2 1.1.6+
0.26.1 1.1.1+
0.26.0 1.1.0+
0.25.1 1.0.17+
0.25.0 1.0.11+
0.24.1 1.0.8+
0.24.0 1.0.7+

Full Documentation

RxScala:

  • The API documentation can be found here.

Note that starting from version 0.15, rx.lang.scala.Observable is not a value class any more. ./Rationale.md explains why.

You can build the API documentation yourself by running sbt doc in the RxScala root directory. Open target/scala-2.11/api/index.html to display it.

RxJava:

Binaries

Binaries and dependency information for Maven, Ivy, Gradle and others can be found at http://search.maven.org.

Example for sbt:

libraryDependencies += "io.reactivex" %% "rxscala" % "0.27.0"

and for Maven:

<dependency>
    <groupId>io.reactivex</groupId>
    <artifactId>rxscala_${scala.compat.version}</artifactId>
    <version>0.27.0</version>
</dependency>

and for Ivy:

<dependency org="io.reactivex" name="rxscala_${scala.compat.version}" rev="0.27.0" />

Build

To build you need sbt:

$ git clone [email protected]:ReactiveX/RxScala.git
$ cd RxScala
$ TRAVIS_TAG=1.0.0-RC1 sbt package

Use TRAVIS_TAG to set the version of the package.

You can also run the examples from within sbt:

$ sbt examples/run

When you see the list of available App objects pick the one you want to execute.

Multiple main classes detected, select one to run:

 [1] AsyncWikiErrorHandling
 [2] SyncObservable
 [3] AsyncObservable
 [4] AsyncWiki
 [5] Transforming

Enter number:

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

LICENSE

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

RxJava

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
Java
47,609
star
2

rxjs

A reactive programming library for JavaScript
TypeScript
30,172
star
3

RxSwift

Reactive Programming in Swift
Swift
24,144
star
4

RxAndroid

RxJava bindings for Android
Java
19,863
star
5

RxKotlin

RxJava bindings for Kotlin
Kotlin
6,993
star
6

RxGo

Reactive Extensions for the Go language.
Go
4,840
star
7

RxPY

ReactiveX for Python
Python
4,677
star
8

rxdart

The Reactive Extensions for Dart
Dart
3,336
star
9

RxCpp

Reactive Extensions for C++
C++
2,949
star
10

RxPHP

Reactive extensions for PHP
PHP
1,680
star
11

learnrx

A series of interactive exercises for learning Microsoft's Reactive Extensions Library for Javascript.
JavaScript
1,403
star
12

RxNetty

Reactive Extension (Rx) Adaptor for Netty
Java
1,383
star
13

IxJS

The Interactive Extensions for JavaScript
TypeScript
1,284
star
14

RxRuby

Reactive Extensions for Ruby
Ruby
959
star
15

RxJavaFX

RxJava bindings for JavaFX
Java
518
star
16

RxRust

The Reactive Extensions for the Rust Programming Language
Rust
478
star
17

RxClojure

RxJava bindings for Clojure
Clojure
357
star
18

rxjs-tslint

TSLint rules targeting RxJS
TypeScript
308
star
19

RxJavaReactiveStreams

Adapter between RxJava and ReactiveStreams
Java
235
star
20

RxJavaDebug

Java
163
star
21

rxjs-docs

The home for new work on the new RxJS docs (RxJS v 5 and up). New to this space? Say hi here: https://github.com/ReactiveX/rxjs-docs/issues/24. Want to find out what's up? We're chatting here. https://github.com/ReactiveX/rxjs-docs/issues/4
TypeScript
161
star
22

RxGroovy

RxJava bindings for Groovy
Groovy
156
star
23

reactivex.github.io

ReactiveX Website
JavaScript
139
star
24

RxJavaAsyncUtil

Java
132
star
25

RxJavaString

Java
130
star
26

RxApacheHttp

RxJava bindings for Apache HTTP
Java
118
star
27

RxJavaJoins

Java
101
star
28

RxJavaMath

Math operators for RxJava.
Java
98
star
29

RxSwing

RxJava bindings for Swing
Java
97
star
30

rxjs-advent-2018

RxJS 2018 Advent Calendar
TypeScript
91
star
31

rxjs-core-notes

Notes from RxJS core meetings
77
star
32

RxJavaFileUtils

File utilities with RxJava
Java
62
star
33

RxJavaComputationExpressions

Java
60
star
34

RxJavaGuava

Java
54
star
35

RxJavaParallel

Experimental Parallel Extensions for RxJava
Java
54
star
36

RxJRuby

RxJava bindings for JRuby
Ruby
37
star
37

Rx.NET

Rx.NET – Reactive Extensions for .NET – a library for composing asynchronous and event-based programs using observable sequences for the CLR.
31
star
38

RxQuasar

RxJava bindings for Quasar
Java
16
star
39

RxRoboVM

RxJava bindings for iOS
Java
7
star
40

BuildInfrastructure

Test project for the new build system.
Groovy
5
star
41

RxSwing2

Reactive bindings for Java 8 Swing on top of RxJava 2
4
star