Packages

implicit class ScalaObservable[T] extends AnyRef

Extends the Java Observable and adds helpers to make Observables composable and simple to Subscribe to.

T

the type of result the Observable emits

Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ScalaObservable
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ScalaObservable(observable: Observable[T])

    observable

    the original Observable

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def andThen[U](pf: PartialFunction[Try[T], U]): Observable[T]

    Applies the side-effecting function to the final result of this Observable and, returns a new Observable with the result of this Observable.

    Applies the side-effecting function to the final result of this Observable and, returns a new Observable with the result of this Observable.

    This method allows one to enforce that the callbacks are executed in a specified order.

    Note that if one of the chained andThen callbacks throws an exception, that exception is not propagated to the subsequent andThen callbacks. Instead, the subsequent andThen callbacks are given the original value of this Observable.

    The following example prints out 10:

    Observable(1 to 10) andThen {
     case r => sys.error("runtime exception")
    } andThen {
     case Success(x) => print(x)
     case Failure(t) => print("Failure")
    }
    U

    the result type of the

    pf

    the partial function to pattern match against

    returns

    an

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  7. def collect[S](): SingleObservable[Seq[T]]

    Collects all the values of the Observable into a list and returns a new Observable with that list.

    Collects all the values of the Observable into a list and returns a new Observable with that list.

    Example:

    val listOfNumbers = Observable(1 to 100).collect()
    returns

    an Observable that emits a single item, the result of accumulator.

    Note

    If the Observable is large then this will consume lots of memory! If the underlying Observable is infinite this Observable will never complete.

    See also

    Uses foldLeft underneath

  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  10. def fallbackTo[U >: T](that: Observable[U]): Observable[U]

    Creates a new Observable which returns the results of this Observable, if there is an error, it will then fallback to returning the results of the alternative "that" Observable.

    Creates a new Observable which returns the results of this Observable, if there is an error, it will then fallback to returning the results of the alternative "that" Observable.

    If both Observables fail, the resulting Observable holds the throwable object of the first Observable.

    Example:

    val fallBackObservable = Observable(1 to 100) fallbackTo Observable(200 to 300)

    Ensuring results from a Single Observer

    fallbackTo can potentially emit results from either Observer. This often isn't desirable, so to ensure only a single Observable issues results combine with the collect method eg:

    val results = Observable(1 to 100).collect() fallbackTo Observable(200 to 300).collect()
    U

    the type of the returned Observable

    that

    the Observable to fallback to if this Observable fails

    returns

    an Observable that will fallback to the that Observable should this Observable complete with an onError.

  11. def filter(predicate: (T) ⇒ Boolean): Observable[T]

    Creates a new Observable by filtering the value of the current Observable with a predicate.

    Creates a new Observable by filtering the value of the current Observable with a predicate.

    If the current Observable fails, then the resulting Observable also fails.

    Example:

    val oddValues = Observable(1 to 100) filter { _ % 2 == 1 }
    predicate

    the function that is applied to each result emitted if it matches that result is passes to the returned Observable

    returns

    an Observable only containing items matching that match the predicate

  12. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. def flatMap[S](mapFunction: (T) ⇒ Observable[S]): Observable[S]

    Creates a new Observable by applying a function to each emitted result of the Observable.

    Creates a new Observable by applying a function to each emitted result of the Observable. If the Observable calls errors then then the new Observable will also contain this exception.

    As each emitted item passed to onNext returns an Observable, we tightly control the requests to the parent Observable. The requested amount is then passed to the child Observable and only when that is completed does the parent become available for requesting more data.

    Example:

    def f = Observable(1 to 10)
    def g = Observable(100 to 100)
    val h = for {
      x: Int <- f // returns Observable(1 to 10)
      y: Int <- g // returns Observable(100 to 100)
    } yield x + y

    is translated to:

    f flatMap { (x: Int) => g map { (y: Int) => x + y } }
    S

    the resulting type of each item in the Observable

    mapFunction

    function that transforms a each result of the receiver into an Observable and passes each result of that Observable to the returned Observable.

    returns

    an Observable with transformed results and / or error.

  14. def foldLeft[S](initialValue: S)(accumulator: (S, T) ⇒ S): SingleObservable[S]

    Creates a new Observable that contains the single result of the applied accumulator function.

    Creates a new Observable that contains the single result of the applied accumulator function.

    The first item emitted by the Observable is passed to the supplied accumulator function alongside the initial value, then all other emitted items are passed along with the previous result of the accumulator function.

    Example:

    val countingObservable = Observable(1 to 100) foldLeft(0)((v, i) => v + 1)
    initialValue

    the initial (seed) accumulator value

    accumulator

    an accumulator function to be invoked on each item emitted by the source Observable, the result of which will be used in the next accumulator call.

    returns

    an Observable that emits a single item, the result of accumulator.

    Note

    If this function is used to collect results into a collection then it could use lots of memory! If the underlying Observable is infinite this Observable will never complete.

  15. def foreach[U](doOnEach: (T) ⇒ U): Unit

    Applies a function applied to each emitted result.

    Applies a function applied to each emitted result.

    Automatically requests all results

    U

    the resulting type after the transformation

    doOnEach

    the anonymous function applied to each emitted item

  16. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. def head(): Future[T]

    Returns the head of the Observable in a scala.concurrent.Future.

    Returns the head of the Observable in a scala.concurrent.Future.

    returns

    the head result of the Observable.

  19. def headOption(): Future[Option[T]]

    Returns the head option of the Observable in a scala.concurrent.Future.

    Returns the head option of the Observable in a scala.concurrent.Future.

    returns

    the head option result of the Observable.

    Since

    2.2

  20. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  21. def map[S](mapFunction: (T) ⇒ S): Observable[S]

    Creates a new Observable by applying a function to each emitted result of the Observable.

    Creates a new Observable by applying a function to each emitted result of the Observable. If the Observable calls errors then then the new Observable will also contain this exception.

    Example:

    def f = Observable(1 to 10)
    def g = Observable(100 to 100)
    val h = for {
      x: Int <- f // returns Observable(1 to 10)
      y: Int <- g // returns Observable(100 to 100)
    } yield x + y

    is translated to:

    f flatMap { (x: Int) => g map { (y: Int) => x + y } }
    S

    the resulting type of each item in the Observable

    mapFunction

    function that transforms a each result of the receiver and passes the result to the returned Observable

    returns

    an Observable with transformed results and / or error.

  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  25. def observeOn(context: ExecutionContext): Observable[T]

    Use a specific execution context for future operations

    Use a specific execution context for future operations

    context

    the execution context

    returns

    an Observable that uses the specified execution context

  26. def recover[U >: T](pf: PartialFunction[Throwable, U]): Observable[U]

    Creates a new Observable that will handle any matching throwable that this Observable might contain.

    Creates a new Observable that will handle any matching throwable that this Observable might contain. If there is no match, or if this Observable contains a valid result then the new Observable will contain the same.

    Example:

    mongoExceptionObservable recover { case e: MongoException => 0 } // final result: 0
    mongoExceptionObservable recover { case e: NotFoundException => 0 } // result: exception
    U

    the type of the returned Observable

    pf

    the partial function used to pattern match against the onError throwable

    returns

    an Observable that will handle any matching throwable and not error.

  27. def recoverWith[U >: T](pf: PartialFunction[Throwable, Observable[U]]): Observable[U]

    Creates a new Observable that will handle any matching throwable that this Observable might contain by assigning it a value of another Observable.

    Creates a new Observable that will handle any matching throwable that this Observable might contain by assigning it a value of another Observable.

    If there is no match, or if this Observable contains a valid result then the new Observable will contain the same result.

    Example:

    successfulObservable recoverWith { case e: ArithmeticException => observableB } // result: successfulObservable
    mongoExceptionObservable recoverWith { case t: Throwable => observableB } // result: observableB

    Ensuring results from a Single Observer

    recoverWith can potentially emit results from either Observer. This often isn't desirable, so to ensure only a single Observable issues results combine with the collect method eg:

    val results = Observable(1 to 100)
      .collect()
      .recoverWith({ case t: Throwable => Observable(200 to 300).collect() })
      .subscribe((i: Seq[Int]) => print(results))
    U

    the type of the returned Observable

    pf

    the partial function used to pattern match against the onError throwable

    returns

    an Observable that will handle any matching throwable and not error but recover with a new observable

  28. def subscribe(doOnNext: (T) ⇒ Any, doOnError: (Throwable) ⇒ Any, doOnComplete: () ⇒ Any): Unit

    Subscribes to the Observable and requests Long.MaxValue.

    Subscribes to the Observable and requests Long.MaxValue.

    Uses the default or overridden onNext, onError, onComplete partial functions.

    doOnNext

    anonymous function to apply to each emitted element.

    doOnError

    anonymous function to apply if there is an error.

    doOnComplete

    anonymous function to apply on completion.

  29. def subscribe(doOnError: (Throwable) ⇒ Any, doOnComplete: () ⇒ Any): Unit

    Subscribes to the Observable and requests Long.MaxValue.

    Subscribes to the Observable and requests Long.MaxValue.

    doOnError

    anonymous function to apply if there is an error.

    doOnComplete

    anonymous function to apply on completion.

  30. def subscribe(doOnNext: (T) ⇒ Any, doOnError: (Throwable) ⇒ Any): Unit

    Subscribes to the Observable and requests Long.MaxValue.

    Subscribes to the Observable and requests Long.MaxValue.

    doOnNext

    anonymous function to apply to each emitted element.

    doOnError

    anonymous function to apply if there is an error.

  31. def subscribe(doOnNext: (T) ⇒ Any): Unit

    Subscribes to the Observable and requests Long.MaxValue.

    Subscribes to the Observable and requests Long.MaxValue.

    doOnNext

    anonymous function to apply to each emitted element.

  32. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  33. def toFuture(): Future[Seq[T]]

    Collects the Observable results and converts to a scala.concurrent.Future.

    Collects the Observable results and converts to a scala.concurrent.Future.

    Automatically subscribes to the Observable and uses the collect method to aggregate the results.

    returns

    a future representation of the whole Observable

    Note

    If the Observable is large then this will consume lots of memory! If the underlying Observable is infinite this Observable will never complete.

  34. def toString(): String
    Definition Classes
    AnyRef → Any
  35. def transform[S](mapFunction: (T) ⇒ S, errorMapFunction: (Throwable) ⇒ Throwable): Observable[S]

    Creates a new Observable by applying the resultFunction function to each emitted result.

    Creates a new Observable by applying the resultFunction function to each emitted result. If there is an error and onError is called the errorFunction function is applied to the failed result.

    S

    the resulting type of each item in the Observable

    mapFunction

    function that transforms a each result of the receiver and passes the result to the returned Observable

    errorMapFunction

    function that transforms a failure of the receiver into a failure of the returned observer

    returns

    an Observable with transformed results and / or error.

  36. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  39. final def withFilter(p: (T) ⇒ Boolean): Observable[T]

    Used by for-comprehensions.

  40. def zip[U](that: Observable[U]): Observable[(T, U)]

    Zips the values of this and that Observable, and creates a new Observable holding the tuple of their results.

    Zips the values of this and that Observable, and creates a new Observable holding the tuple of their results.

    If this Observable fails, the resulting Observable is failed with the throwable stored in this. Otherwise, if that Observable fails, the resulting Observable is failed with the throwable stored in that.

    It will only emit as many items as the number of items emitted by the source Observable that emits the fewest items.

    U

    the type of the that Observable

    that

    the Observable to zip with

    returns

    a new zipped Observable

Inherited from AnyRef

Inherited from Any

Ungrouped