Skip to content

Instantly share code, notes, and snippets.

@lawloretienne
Last active September 23, 2018 11:19
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save lawloretienne/40959a8d95c8d0bf4675999d07df3c0c to your computer and use it in GitHub Desktop.
Save lawloretienne/40959a8d95c8d0bf4675999d07df3c0c to your computer and use it in GitHub Desktop.
  • Functional Programming is a model of programming that transform and compose stream of immutable sequences by applying map, filter and reduce. Events are immutable because you can't change history.
  • Reactive Programming is a model of programming focuses on data flow and change propagation.
  • ReactiveX is an API that focuses on asynchronous composition and manipulation of observable streams of data or events by using a combination of the Observer pattern, Iterator pattern, and features of Functional Programming.
  • RxJava is the open-source implementation of ReactiveX in Java.
  • RxJava is a Java VM implementation of ReactiveX (Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.
  • RxAndroid is a lightweight extension to RxJava that providers a Scheduler for Android’s Main Thread, as well as the ability to create a Scheduler that runs on any given Android Handler class.
  • The two main classes are Observable and Subscriber.
  • Observable is a class that emits a stream of data or events.
  • Subscriber is a class that acts upon the emitted items.
  • A cold observable is one to which no one has subscribed, and is thus inanimate.
  • Observable subscribe has many overloads. You can choose to implement an entire Observer with onNext, onComplete and onError, or only some of these in the form of an Action1.
  • Using Observable.subscribeOn() can define a thread that will run our Observable’s code (the long running operation).
  • Using Observable.observeOn() can define a thread that is used to monitor and check for newly emitted items from the Observable (the Subscriber’s onNext, onCompleted, and onError methods execute on the observeOn() thread).
  • RxJava comes with several out-of-the-box Schedulers to use with Observables, such as Schedulers.io() (for blocking I/O operations), Schedulers.computation() (computational work), and Schedulers.newThread() (creates new thread for the work).
  • Rx was first conceived by Erik Meijer on the Microsoft .NET platform, as a way of combining data or event streams with reactive objects and functional composition
  • In Rx, events are modeled as observable streams to which observers are subscribed. These streams, or observables for short, can be filtered, transformed, and composed in various ways before their results are emitted to an observer.
  • The standard flow of an Observable is to emit one or more items, and then complete successfully or with an error.
  • An Observable can have multiple Subscribers, and for each item emitted by the Observable, the item will be sent to the Subscriber.onNext() method to be handled.
  • Once an Observable has finished emitting items, it will call the Subscriber.onCompleted() method, or if there is an error the Observable will call the Subscriber.onError() method.
  • RxJava, at it’s core, is about two things: Observables and Observers.
  • Observables are said to “emit” values.
  • Observers, watch Observables by “subscribing” to them.
  • When an Observer subscribes to an Observable a Subscription is created.
  • A Subscription represents a connection between an Observer and an Observable.
  • Subjects are special objects that are both an Observable and an Observer.
  • The basic building blocks of reactive code are Observables and Subscribers.
  • An Observable emits items; a Subscriber consumes those items.
  • Schedulers decide on which thread actions are executed.
  • RxJava provides 2 operators to specify Scheduler : subscribeOn - specify the Scheduler on which an Observable will operate. observeOn - specify the Scheduler on which an observer will observe this Observable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment