7. Introduction
● It is a declarative programming paradigm, which means programming is
done with expressions.
● Functional code, the output value of a function depends only on the
arguments that are input to the function.
32. Introduction
● Defines a “one-to-many” dependency between objects so that when one
object changes state, all its dependents are notified and updated.
● Subject: the object which will frequently change its state and upon
which other objects depend.
● Observer: the object which depends on a subject and updates according
to its subject’s state.
35. Agenda
● Functional Programming (java 8)
○ Getting Started
○ Examples
● Observer Pattern
○ Introduction
○ Real life example
○ UML
● ReactiveX
○ Introduction
○ Getting Started
○ Example
○ Operators
36. ReactiveX
ReactiveX is a combination of the best ideas from
the Observer pattern, the Iterator pattern, and functional programming
37. Introduction
● Reactive programming is a programming paradigm
oriented around data flows and propagation of change.
● Let:
a = b + c
what about if b or c has been changed?!
38. Introduction
● Functional Reactive programming (FRP) is a style of
programming based on two keys ideas: continuous
time-varying behaviors, and event based reactively.
● Popularized by Erik Meijer when he created the Rx
library for .Net while at Microsoft.
40. What Are Reactive Extensions?
● It’s a library that allows you to use FRP at many
programming languages.
● Allows you to represent asynchronous data streams
with “Observables”.
● And Parametrize the concurrency in those
asynchronous data streams using “Schedulers”
41. Rx Family
● C#: Rx.NET
● Javascript: RxJS
● RxJava (Java, Scala, Groovy, Clojure, Kotlin).
● Ruby: Rx.rb
● Python: RxPY
● More at http://reactivex.io/
42. Why Functional Reactive Programming?
● Writing concurrent programs correctly is difficult.
● You can transform & compose asynchronous operations.
● High-level abstraction.
● Standard error handling.
44. Observables and Observer
● In ReactiveX an Observer subscribes to an Observable.
● Then That Observer reacts to whatever item or sequence of items the
Observable emits.
● This patterns facilitate concurrent operations because it does not need
to block while waiting for the observable.
45. Observer onNext, onCompleted, onError
An Observer implements a subset of the following methods:
● onNext: We call this method whenever the Observable emits an item.
● onError: Call this method to indicate the the observable has failed and
will not make further calls to onNext or onCompleted.
● onCompleted: Call this method after you have called onNext for the final
time and if we have not encountered any errors.
47. RxJava
● It’s a JVM implementation of Reactive Extensions.
● Started at Netflix but now Open Sourced.
● Supports Java 6+ & Android 2.3+.
● Java 8 lambda support.