rxjs vs rxjava: intro

Post on 09-Jan-2017

745 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

RxJS vs RxJavaIntro

Agenda

• Reactive Programming• Functional Reactive Programming• RxJS• RxJava

Reactive Programming

Reactive Programming

• In imperative programming languages expressions are evaluated “in place”:

a = 10;b = 20;c = a + b; // c = 30a = 40; // c = 30

Reactive Programming

• In reactive programming languages changes in the data flow may trigger changes to multiple variables:

a = 10;b = 20;c = a + b; // c = 30a = 40; // c = 60

Reactive Programming

• Reactive programming may also refer to the interaction between different systems or components in a system

• In that regard the libraries we will be discussing do not serve as a replacement of message brokers (such as RabbitMQ, Kafka, MSMQ and a number of others)

Reactive Programming

• In this clash we would refer to the “programming language” - inferred meaning behind reactive programming

Reactive Programming

• The Reactive Manifesto:

Functional Reactive Programming

Functional Reactive Programming

• A more common subset is functional reactive programming (FRP) that makes use of streams and stream operations for anything (input, changes in variables and many more) in order to achieve reactiveness

• Connal Elliot – ground-breaking paper @Conference on Functional Programming, 1997

Functional Reactive Programming

•Reactive Programming = Programming with Asynchronous Data Streams

•Functional Reactive Programming (FRP) = programming paradigm for reactive programming that uses the building blocks of functional programming (e.g. map, reduce, filter). FRP has been used for programming graphical user interfaces (GUIs), robotics, and music, aiming to simplify these problems by explicitly modeling time. [Wikipedia]

Functional Reactive Programming

•Reactive Programming = Programming with Asynchronous Data Streams

•Functional Reactive Programming (FRP) = programming paradigm for reactive programming that uses the building blocks of functional programming (e.g. map, reduce and filter)

Functional Reactive Programming

• FRP has been used in:

– responsive graphical user interfaces (GUIs)

– robotics

– the music industry

Functional Reactive Programming

• RxJava and RxJS implement the functional reactive programming paradigm in terms of libraries for the Java and JavaScript programming languages correspondingly …

• Derived on the basis of Microsoft’s Reactive Extensions (Rx) library for .NET

Functional Reactive Programming

Microsoft® open source polyglot project ReactiveX (Reactive Extensions) [http://reactivex.io]: Rx = Observables + LINQ + Schedulers :)• Supported Languages – Java: RxJava, JavaScript: RxJS, C#:

Rx.NET, C#(Unity): UniRx, Scala: RxScala, Clojure: RxClojure, C++: RxCpp, Ruby: Rx.rb, Python: RxPY, Groovy: RxGroovy, JRuby: RxJRuby, Kotlin: RxKotlin, Swift: RxSwift

• ReactiveX for platforms and frameworks: RxNetty, RxAndroid, RxCocoa

Functional Reactive Programming

• Rx has an implicit contract that must be followed:

event source

OnNext(item) OnNext(item) OnNext(item)

OnCompleted()

OnError(Exception)

RxJS

RxJsRx.Observable.from(["Reactive", "Extensions", "Java“])

.take(2) .map(function(s) { s + " : on " + new Date()})

.subscribe(function(s) {console.log(s)});

Result: Reactive : on Wed Jun 17 21:54:02 GMT+02:00 2015

Extensions : on Wed Jun 17 21:54:02 GMT+02:00 2015

RxJava

RxJava

Observable.from(new String[] {"Reactive", "Extensions", "Java"})

.take(2) .map(s -> s + " : on " + new Date()) .subscribe(s -> System.out.println(s));

Result: Reactive : on Wed Jun 17 21:54:02 GMT+02:00 2015

Extensions : on Wed Jun 17 21:54:02 GMT+02:00 2015

RxJava

• Lambdas and streams introduced in Java 8 make the FRP style of programming in Java easier to accomplish

• There is a proposal for introducing a reactive streaming API as part of the core libraries in JDK 9

top related