3

Documentation is pretty clear about what this alternative of Observable doing:

The Single class implements the Reactive Pattern for a single value response. See Observable for the implementation of the Reactive Pattern for a stream or vector of values. Single behaves the same as Observable except that it can only emit either a single successful value or an error (there is no "onComplete" notification as there is for Observable) Like an Observable, a Single is lazy, can be either "hot" or "cold", synchronous or asynchronous.

But I can't see a reason apart that it is might be simpler then Observable sometimes, where and why to use it?

ar-g
  • 3,417
  • 2
  • 28
  • 39
  • 1
    I would recommend listening to The Context podcast, episode 3. The host talks there with David Karnok (one of the main contributors to RxJava project) about this subject. Basically, this one has been created so you could better express yourself when writing code. There is nothing really special about it and afaik it heavily relies on the Observables anyway. You could use Single for example for simple network calls (where you'd expect only one response anyway). Keep in mind that Single is still annotated as Beta. [Link to the podcast](https://github.com/artem-zinnatullin/TheContext-Podcast) – scana Mar 25 '16 at 07:56

1 Answers1

3

There are cases where it makes sense for an observable to only return a single item and end (or error). This blog post explains it succinctly.

JohnWowUs
  • 3,053
  • 1
  • 13
  • 20