Skip to content

Commit add46e6

Browse files
put unapply of Notifications into companions
no more scalac crash
1 parent f7ab0b3 commit add46e6

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import org.junit.{Before, Test, Ignore}
2323
import org.junit.Assert._
2424
import rx.lang.scala.concurrency.NewThreadScheduler
2525
import rx.lang.scala.util.Timestamped
26+
import java.io.IOException
2627

27-
//@Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
28+
@Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
2829
class RxScalaDemo extends JUnitSuite {
2930

3031
@Test def intervalExample() {
@@ -385,13 +386,17 @@ class RxScalaDemo extends JUnitSuite {
385386

386387
@Test def materializeExample() {
387388
def printObservable[T](o: Observable[T]): Unit = {
389+
import Notification._
388390
for (n <- o.materialize.toBlockingObservable) n match {
389-
case Notification.OnNext[T](v) => println("Got value " + v)
390-
case Notification.OnCompleted[T]() => println("Completed")
391-
case Notification.OnError[T](err) => println("Error: ")
392-
}
391+
case OnNext(v) => println("Got value " + v)
392+
case OnCompleted() => println("Completed")
393+
case OnError(err) => println("Error: " + err.getMessage)
394+
}
393395
}
394-
val mat = Observable.interval(100 millis).take(3).materialize
396+
val o1 = Observable.interval(100 millis).take(3)
397+
val o2 = o1 ++ Observable(new IOException("Oops"))
398+
printObservable(o1)
399+
printObservable(o2)
395400
}
396401

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

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ object Notification {
1717

1818
class OnNext[+T](val asJava: rx.Notification[_ <: T]) extends Notification[T] {
1919
def value: T = asJava.getValue
20+
}
21+
22+
object OnNext {
2023
def unapply[U](n: Notification[U]): Option[U] = n match {
2124
case n2: OnNext[U] => Some(n.asJava.getValue)
2225
case _ => None
@@ -25,13 +28,18 @@ object Notification {
2528

2629
class OnError[+T](val asJava: rx.Notification[_ <: T]) extends Notification[T] {
2730
def error: Throwable = asJava.getThrowable()
31+
}
32+
33+
object OnError {
2834
def unapply[U](n: Notification[U]): Option[Throwable] = n match {
2935
case n2: OnError[U] => Some(n2.asJava.getThrowable)
3036
case _ => None
3137
}
3238
}
3339

34-
class OnCompleted[T](val asJava: rx.Notification[_ <: T]) extends Notification[T] {
40+
class OnCompleted[T](val asJava: rx.Notification[_ <: T]) extends Notification[T] {}
41+
42+
object OnCompleted {
3543
def unapply[U](n: Notification[U]): Option[Unit] = n match {
3644
case n2: OnCompleted[U] => Some()
3745
case _ => None

0 commit comments

Comments
 (0)