Skip to content

Commit d3f933c

Browse files
improve scaladoc
1 parent f1a3fb2 commit d3f933c

File tree

13 files changed

+90
-45
lines changed

13 files changed

+90
-45
lines changed

language-adaptors/rxjava-scala/README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,12 @@ For more examples, see [RxScalaDemo.scala](https://github.com/Netflix/RxJava/blo
6262

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

65-
Work on this adaptor is still in progress, and for the moment, the best source of documentation are the comments in the source code of [`rx.lang.scala.Observable`](https://github.com/Netflix/RxJava/blob/master/language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Observable.scala).
66-
6765

6866
## Documentation
6967

70-
You can build the documentation as follows: In the RxJava root directory, run
71-
72-
./gradlew :language-adaptors:rxjava-scala:scaladoc
73-
74-
Then navigate to
68+
You can build the documentation by running `./gradlew scaladoc` in the RxJava root directory.
7569

76-
RxJava/language-adaptors/rxjava-scala/build/docs/scaladoc/index.html
70+
Then navigate to `RxJava/language-adaptors/rxjava-scala/build/docs/scaladoc/index.html` to display it.
7771

7872

7973
## Binaries

language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/RxScalaDemo.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,31 @@ class RxScalaDemo extends JUnitSuite {
384384
}
385385
}
386386

387-
@Test def materializeExample() {
387+
@Test def materializeExample1() {
388388
def printObservable[T](o: Observable[T]): Unit = {
389389
import Notification._
390-
for (n <- o.materialize.toBlockingObservable) n match {
390+
o.materialize.subscribe(n => n match {
391391
case OnNext(v) => println("Got value " + v)
392392
case OnCompleted() => println("Completed")
393393
case OnError(err) => println("Error: " + err.getMessage)
394-
}
394+
})
395395
}
396+
396397
val o1 = Observable.interval(100 millis).take(3)
397-
val o2 = o1 ++ Observable(new IOException("Oops"))
398+
val o2 = Observable(new IOException("Oops"))
398399
printObservable(o1)
400+
waitFor(o1)
399401
printObservable(o2)
402+
waitFor(o2)
403+
}
404+
405+
@Test def materializeExample2() {
406+
import Notification._
407+
Observable(1, 2, 3).materialize.subscribe(n => n match {
408+
case OnNext(v) => println("Got value " + v)
409+
case OnCompleted() => println("Completed")
410+
case OnError(err) => println("Error: " + err.getMessage)
411+
})
400412
}
401413

402414
def output(s: String): Unit = println(s)

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/ImplicitFunctionConversions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import java.{ lang => jlang }
1919
import rx.util.functions._
2020

2121
/**
22-
* These function conversions convert between Scala functions and Rx Funcs and Actions.
23-
* Most users RxScala won't need them, but they might be useful if one wants to use
24-
* the rx.Observable directly instead of using rx.lang.scala.Observable or if one wants
25-
* to use a Java library taking/returning Funcs and Actions.
22+
* These function conversions convert between Scala functions and Rx `Func`s and `Action`s.
23+
* Most RxScala users won't need them, but they might be useful if one wants to use
24+
* the `rx.Observable` directly instead of using `rx.lang.scala.Observable` or if one wants
25+
* to use a Java library taking/returning `Func`s and `Action`s.
2626
*/
2727
object ImplicitFunctionConversions {
2828
import language.implicitConversions

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Notification.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
package rx.lang.scala
22

3+
/**
4+
* Emitted by Observables returned by [[rx.lang.scala.Observable.materialize]].
5+
*/
36
sealed trait Notification[+T] {
47
def asJava: rx.Notification[_ <: T]
58
}
69

10+
/**
11+
* Provides pattern matching support for Notifications.
12+
*
13+
* Example:
14+
* {{{
15+
* import Notification._
16+
* Observable(1, 2, 3).materialize.subscribe(n => n match {
17+
* case OnNext(v) => println("Got value " + v)
18+
* case OnCompleted() => println("Completed")
19+
* case OnError(err) => println("Error: " + err.getMessage)
20+
* })
21+
* }}}
22+
*/
723
object Notification {
824

925
def apply[T](n: rx.Notification[_ <: T]): Notification[T] = n.getKind match {

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Observable.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package rx.lang.scala
2020
/**
2121
* The Observable interface that implements the Reactive Pattern.
2222
*/
23-
class Observable[+T](val asJava: rx.Observable[_ <: T])
23+
class Observable[+T] private[scala] (val asJava: rx.Observable[_ <: T])
2424
// Uncommenting this line combined with `new Observable(...)` instead of `new Observable[T](...)`
2525
// makes the compiler crash
2626
extends AnyVal
@@ -641,7 +641,8 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
641641
}
642642

643643
/**
644-
* <p>
644+
* Returns an Observable which only emits those items for which a given predicate holds.
645+
*
645646
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/filter.png">
646647
*
647648
* @param predicate
@@ -1278,7 +1279,7 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
12781279
* @param that
12791280
* an Observable to be merged
12801281
* @return an Observable that emits items that are the result of flattening the items emitted by
1281-
* {$code this} and {$code that}
1282+
* {@code this} and {@code that}
12821283
*/
12831284
def mergeDelayError[U >: T](that: Observable[U]): Observable[U] = {
12841285
Observable[U](rx.Observable.mergeDelayError[U](this.asJava, that.asJava))
@@ -1761,6 +1762,9 @@ class Observable[+T](val asJava: rx.Observable[_ <: T])
17611762

17621763
}
17631764

1765+
/**
1766+
* Provides various ways to construct new Observables.
1767+
*/
17641768
object Observable {
17651769
import scala.collection.JavaConverters._
17661770
import scala.collection.immutable.Range
@@ -1982,7 +1986,7 @@ object Observable {
19821986
// Cannot yet have inner class because of this error message:
19831987
// "implementation restriction: nested class is not allowed in value class.
19841988
// This restriction is planned to be removed in subsequent releases."
1985-
class WithFilter[+T] private[scala] (p: T => Boolean, asJava: rx.Observable[_ <: T]) {
1989+
private[scala] class WithFilter[+T] (p: T => Boolean, asJava: rx.Observable[_ <: T]) {
19861990
import rx.lang.scala.ImplicitFunctionConversions._
19871991

19881992
def map[B](f: T => B): Observable[B] = {
@@ -2000,7 +2004,7 @@ class WithFilter[+T] private[scala] (p: T => Boolean, asJava: rx.Observable[_ <:
20002004
// there is no foreach here, that's only available on BlockingObservable
20012005
}
20022006

2003-
class UnitTestSuite extends org.scalatest.junit.JUnitSuite {
2007+
private[scala] class UnitTestSuite extends org.scalatest.junit.JUnitSuite {
20042008
import scala.concurrent.duration._
20052009
import org.junit.{Before, Test, Ignore}
20062010
import org.junit.Assert._

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/concurrency/Schedulers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ object Schedulers {
2525
def newThread: Scheduler = rx.concurrency.Schedulers.newThread
2626

2727
/**
28-
* Returns a [[rx.lang.scala.Scheduler]] that queues work on an [[java.util.concurrent.Executor]].
28+
* Returns a [[rx.lang.scala.Scheduler]] that queues work on an `java.util.concurrent.Executor`.
2929
*
3030
* Note that this does not support scheduled actions with a delay.
3131
*/
3232
def executor(executor: Executor): Scheduler = rx.concurrency.Schedulers.executor(executor)
3333

3434
/**
35-
* Returns a [[rx.lang.scala.Scheduler]] that queues work on an [[java.util.concurrent.ScheduledExecutorService]].
35+
* Returns a [[rx.lang.scala.Scheduler]] that queues work on an `java.util.concurrent.ScheduledExecutorService`.
3636
*/
3737
def executor(executor: ScheduledExecutorService): Scheduler = rx.concurrency.Schedulers.executor(executor)
3838

3939
/**
4040
* Returns a [[rx.lang.scala.Scheduler]] intended for computational work.
4141
*
42-
* The implementation is backed by a [[java.util.concurrent.ScheduledExecutorService]] thread-pool sized to the number of CPU cores.
42+
* The implementation is backed by a `java.util.concurrent.ScheduledExecutorService` thread-pool sized to the number of CPU cores.
4343
*
4444
* This can be used for event-loops, processing callbacks and other computational work.
4545
*
@@ -50,7 +50,7 @@ object Schedulers {
5050
/**
5151
* [[rx.lang.scala.Scheduler]] intended for IO-bound work.
5252
*
53-
* The implementation is backed by an [[java.util.concurrent.Executor]] thread-pool that will grow as needed.
53+
* The implementation is backed by an `java.util.concurrent.Executor` thread-pool that will grow as needed.
5454
*
5555
* This can be used for asynchronously performing blocking IO.
5656
*

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/concurrency/package.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ package rx.lang.scala
1717

1818
import rx.concurrency.CurrentThreadScheduler
1919

20+
/**
21+
* Provides schedulers.
22+
*/
2023
package object concurrency {
2124
// These classes are not exposed to Scala users, but are accessible through
2225
// rx.lang.scala.concurrency.Schedulers:

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/observables/BlockingObservable.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import rx.lang.scala.ImplicitFunctionConversions._
2323
*
2424
* You can obtain a BlockingObservable from an Observable using [[Observable.toBlockingObservable]]
2525
*/
26-
class BlockingObservable[+T](val asJava: rx.observables.BlockingObservable[_ <: T])
26+
class BlockingObservable[+T] private[scala] (val asJava: rx.observables.BlockingObservable[_ <: T])
2727
extends AnyVal
2828
{
2929

@@ -131,7 +131,7 @@ class BlockingObservable[+T](val asJava: rx.observables.BlockingObservable[_ <:
131131
// Cannot yet have inner class because of this error message:
132132
// "implementation restriction: nested class is not allowed in value class.
133133
// This restriction is planned to be removed in subsequent releases."
134-
class WithFilter[+T] private[observables] (p: T => Boolean, asJava: rx.observables.BlockingObservable[_ <: T]) {
134+
private[observables] class WithFilter[+T] (p: T => Boolean, asJava: rx.observables.BlockingObservable[_ <: T]) {
135135
import rx.lang.scala.ImplicitFunctionConversions._
136136

137137
// there's no map and flatMap here, they're only available on Observable

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/observables/package.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package rx.lang.scala
44
* Contains special Observables.
55
*
66
* In Scala, this package only contains [[rx.lang.scala.observables.BlockingObservable]].
7-
* In the corresponding Java package {{{rx.observables}}}, there is also a
8-
* {{{GroupedObservable}}} and a {{{ConnectableObservable}}}, but these are not needed
9-
* in Scala, because we use a pair {{{(key, observable)}}} instead of {{{GroupedObservable}}}
10-
* and a pair {{{(startFunction, observable)}}} instead of {{{ConnectableObservable}}}.
7+
* In the corresponding Java package `rx.observables`, there is also a
8+
* `GroupedObservable` and a `ConnectableObservable`, but these are not needed
9+
* in Scala, because we use a pair `(key, observable)` instead of `GroupedObservable`
10+
* and a pair `(startFunction, observable)` instead of `ConnectableObservable`.
1111
*/
1212
package object observables {}

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/package.scala

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
*/
1616
package rx.lang
1717

18+
import java.util.concurrent.TimeUnit
19+
import java.util.Date
1820

19-
/**
20-
* This object contains aliases to all types Scala users need to import.
21-
*
21+
/*
2222
* Note that:
23-
* - Scala users cannot use Java's type with variance without always using writing
23+
* - Scala users cannot use Java's types with variance without always using writing
2424
* e.g. rx.Notification[_ <: T], so we create aliases fixing the variance
25-
* - For consistency, we create aliases for all types
25+
* - For consistency, we create aliases for all types which Scala users need
26+
*/
27+
28+
/**
29+
* This package contains all classes that RxScala users need.
30+
*
31+
* It mirrors the structure of package `rx`, but implementation classes that RxScala users
32+
* will not need are left out.
2633
*/
27-
import java.util.concurrent.TimeUnit
28-
import java.util.Date
2934
package object scala {
3035

3136
/*
@@ -45,23 +50,23 @@ package object scala {
4550
/**
4651
* Provides a mechanism for receiving push-based notifications.
4752
*
48-
* After an Observer calls an [[rx.lang.scala.Observable]]'s {{{subscribe}}} method, the Observable
49-
* calls the Observer's {{{onNext}}} method to provide notifications. A well-behaved Observable will
50-
* call an Observer's {{{onCompleted}}} method exactly once or the Observer's {{{onError}}} method exactly once.
53+
* After an Observer calls an [[rx.lang.scala.Observable]]'s `subscribe` method, the Observable
54+
* calls the Observer's `onNext` method to provide notifications. A well-behaved Observable will
55+
* call an Observer's `onCompleted` method exactly once or the Observer's `onError` method exactly once.
5156
*/
5257
trait Observer[-T] {
5358
5459
/**
5560
* Notifies the Observer that the [[rx.lang.scala.Observable]] has finished sending push-based notifications.
5661
*
57-
* The [[rx.lang.scala.Observable]] will not call this method if it calls {{{onError}}}.
62+
* The [[rx.lang.scala.Observable]] will not call this method if it calls `onError`.
5863
*/
5964
def onCompleted(): Unit
6065
6166
/**
6267
* Notifies the Observer that the [[rx.lang.scala.Observable]] has experienced an error condition.
6368
*
64-
* If the [[rx.lang.scala.Observable]] calls this method, it will not thereafter call {{{onNext}}} or {{{onCompleted}}}.
69+
* If the [[rx.lang.scala.Observable]] calls this method, it will not thereafter call `onNext` or `onCompleted`.
6570
*/
6671
def onError(e: Throwable): Unit
6772
@@ -70,7 +75,7 @@ package object scala {
7075
*
7176
* The [[rx.lang.scala.Observable]] calls this closure 0 or more times.
7277
*
73-
* The [[rx.lang.scala.Observable]] will not call this method again after it calls either {{{onCompleted}}} or {{{onError}}}.
78+
* The [[rx.lang.scala.Observable]] will not call this method again after it calls either `onCompleted` or `onError`.
7479
*/
7580
def onNext(arg: T): Unit
7681
}
@@ -201,6 +206,8 @@ package object scala {
201206
def unsubscribe(): Unit
202207
}
203208
209+
import language.implicitConversions
210+
204211
private[scala] implicit def fakeSubscription2RxSubscription(s: Subscription): rx.Subscription =
205212
new rx.Subscription {
206213
def unsubscribe() = s.unsubscribe()

0 commit comments

Comments
 (0)