SlideShare a Scribd company logo
Functional Reactive
Programming
BY: AHMED KAMEL TAHA
Functional Programming
Evaluation of mathematical functions
■ Avoid mutable state
■ Referential transparency
■ Avoid side-effects
■ Reusable functions over reusable object
■ Function composition over object composition
Reactive Programming
A programming paradigm that helps you to build ‘Reactive Systems’. E.g.: Google Spreadsheet
• In a reactive world, we can't just wait for a function result, a network call, or a database query
to return.
• Every moment we wait for something, we lose the opportunity to do other things in parallel.
• Reactive programming can be done in several ways
◦ • Akka Actors
◦ • Reactive Extensions (Rx) – reactive + functional
Why Reactive Programming?
Why another programming paradigm?
• Things are different now!
• Conventional software applications won’t be able to fulfill the modern enterprise needs.
• Its time to rethink about our software architecture patterns and programming techniques.
What it actually means to be Reactive?
“Readily responsive to a stimulus” - merriam-webster
Reactive Systems :
•responds in a timely manner
•stays responsive in the face of failure
•stays responsive under varying workload
•rely on asynchronous message-passing
Functional Programming
 map
 filter
 mergeAll
 reduce
 zip
Map
Filter
Map & Filter
MergeAll
FlatMap
Reduce
Zip
Reactive Programming
 Asynchronous data streams
 Everything is a stream
 click events
 user inputs
 data from a server
Observables
o Stream of data over time
o Hot vs Cold Observables
o Asynchronous
o Lazy
o queryable, bufferable, pausable…
o more than 120 operations
Observable and Operators
Observable Creation
Observable Basics
Observable Basics
Cold Observables
• Hot observables are pushing even when we are not
subscribed to them (e.g., UI events).
Hot Observables
• Cold observables start pushing only when we
subscribe. They start over if we subscribe again.
Autocomplete
Autocomplete
RxJS
Supported
◦ IE6+
◦ Chrome 4+
◦ FireFox 1+
◦ Node.js v0.4+
Size (minified & gzipped):
◦ all - 23,1k
◦ lite - 13,5k
◦ compat - 12,5k
◦ ES5 core - 12k
Framework Bridges
 AngularJS
 ReactJS
 jQuery
 ExtJS
 NodeJS
 Backbone
Alternatives to RxJS
 BaconJS
 Kefir
 (Elm)
Conclusion
 There is a learning curve
 Great abstraction for async & events
 Improves
 Readability
 Reusability
 Scalability
 Both on the front- and backend
Thank You
ANY QUESTIONS?

More Related Content

Functional reactive programming