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 ofReactiveX
in Java.RxJava
is a Java VM implementation ofReactiveX
(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
andSubscriber
. 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 entireObserver
withonNext
,onComplete
andonError
, or only some of these in the form of anAction1
. - 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 asSchedulers.io()
(for blocking I/O operations),Schedulers.computation()
(computational work), andSchedulers.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 whichobservers
aresubscribed
. These streams, or observables for short, can befiltered
,transformed
, andcomposed
in various ways before their results areemitted
to anobserver
. - 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 multipleSubscribers
, and for each item emitted by theObservable
, the item will be sent to theSubscriber.onNext()
method to be handled. - Once an
Observable
has finished emitting items, it will call theSubscriber.onCompleted()
method, or if there is an error theObservable
will call theSubscriber.onError()
method. RxJava
, at it’s core, is about two things:Observables
andObservers
.Observables
are said to “emit” values.Observers
, watchObservables
by “subscribing” to them.- When an
Observer
subscribes to anObservable
aSubscription
is created. - A
Subscription
represents a connection between anObserver
and anObservable
. Subjects
are special objects that are both anObservable
and anObserver
.- The basic building blocks of reactive code are
Observables
andSubscribers
. - An
Observable
emits items; aSubscriber
consumes those items. Schedulers
decide on which thread actions are executed.RxJava
provides 2 operators to specifyScheduler
:subscribeOn
- specify theScheduler
on which anObservable
will operate.observeOn
- specify theScheduler
on which an observer will observe thisObservable
.
Last active
September 23, 2018 11:19
-
-
Save lawloretienne/40959a8d95c8d0bf4675999d07df3c0c to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment