Skip to content

Commit 402fbec

Browse files
restore original README.md
1 parent 2cdbbca commit 402fbec

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Scala Adaptor for RxJava
2+
3+
This adaptor allows to use RxJava in Scala with anonymous functions, e.g.
4+
5+
```scala
6+
val o = Observable.interval(200 millis).take(5)
7+
o.subscribe(n => println("n = " + n))
8+
Observable(1, 2, 3, 4).reduce(_ + _)
9+
```
10+
11+
For-comprehensions are also supported:
12+
13+
```scala
14+
val first = Observable(10, 11, 12)
15+
val second = Observable(10, 11, 12)
16+
val booleans = for ((n1, n2) <- (first zip second)) yield (n1 == n2)
17+
```
18+
19+
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:
20+
21+
```scala
22+
// instead of concat:
23+
def ++[U >: T](that: Observable[U]): Observable[U]
24+
25+
// instance method instead of static:
26+
def zip[U](that: Observable[U]): Observable[(T, U)]
27+
28+
// the implicit evidence argument ensures that dematerialize can only be called on Observables of Notifications:
29+
def dematerialize[U](implicit evidence: T <:< Notification[U]): Observable[U]
30+
31+
// additional type parameter U with lower bound to get covariance right:
32+
def onErrorResumeNext[U >: T](resumeFunction: Throwable => Observable[U]): Observable[U]
33+
34+
// curried in Scala collections, so curry fold also here:
35+
def fold[R](initialValue: R)(accumulator: (R, T) => R): Observable[R]
36+
37+
// using Duration instead of (long timepan, TimeUnit duration):
38+
def sample(duration: Duration): Observable[T]
39+
40+
// called skip in Java, but drop in Scala
41+
def drop(n: Int): Observable[T]
42+
43+
// there's only mapWithIndex in Java, because Java doesn't have tuples:
44+
def zipWithIndex: Observable[(T, Int)]
45+
46+
// corresponds to Java's toList:
47+
def toSeq: Observable[Seq[T]]
48+
49+
// the implicit evidence argument ensures that switch can only be called on Observables of Observables:
50+
def switch[U](implicit evidence: Observable[T] <:< Observable[Observable[U]]): Observable[U]
51+
52+
// Java's from becomes apply, and we use Scala Range
53+
def apply(range: Range): Observable[Int]
54+
55+
// use Bottom type:
56+
def never: Observable[Nothing]
57+
```
58+
59+
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).
60+
61+
For more examples, see [RxScalaDemo.scala](https://github.com/Netflix/RxJava/blob/master/language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/RxScalaDemo.scala).
62+
63+
Scala code using Rx should only import members from `rx.lang.scala` and below.
64+
65+
66+
## Documentation
67+
68+
The API documentation can be found [here](http://rxscala.github.io/scaladoc/index.html#rx.lang.scala.Observable).
69+
70+
You can build the API documentation yourself by running `./gradlew scaladoc` in the RxJava root directory.
71+
72+
Then navigate to `RxJava/language-adaptors/rxjava-scala/build/docs/scaladoc/index.html` to display it.
73+
74+
75+
## Binaries
76+
77+
Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22rxjava-scala%22).
78+
79+
Example for Maven:
80+
81+
```xml
82+
<dependency>
83+
<groupId>com.netflix.rxjava</groupId>
84+
<artifactId>rxjava-scala</artifactId>
85+
<version>x.y.z</version>
86+
</dependency>
87+
```
88+
89+
and for Ivy:
90+
91+
```xml
92+
<dependency org="com.netflix.rxjava" name="rxjava-scala" rev="x.y.z" />
93+
```
94+
95+
and for sbt:
96+
97+
```scala
98+
libraryDependencies ++= Seq(
99+
"com.netflix.rxjava" % "rxjava-scala" % "x.y.z"
100+
)
101+
```

0 commit comments

Comments
 (0)