SlideShare a Scribd company logo
Reactive Programming
Buğra Uluyurt
Programming Types
Hardest part while learning Reactive
Programming => THINKING IN REACTIVE
Programming Types
- Imperative (Stateful)
- Declarative - Functional (Stateless)
- Reactive
Programming Types
IMPERATIVE
Imperative programming is a programming paradigm that uses statements that change a
program’s state.
Programming Types
DECLARATIVE
Declarative programming is a programming paradigm … that expresses the logic of a
computation without describing its control flow.
Programming Types
REACTIVE
- Wikipedia => it is like a description in a CS book which is generic and theoretical
- Reactive manifesto => it is so generic for a developer with dirty hands
- Stackoverlow => Look at stackoverflow and never look back to reactive
programming again. Morale killing explanations, hard and most advanced stuff
without explaining its core.
Reactive programming is programming with asynchronous data streams
Nothing new just made easier!
It is like dealing with event streams such as =>
- Event buses
- Click events
Streams are cheap, anything can be a stream:
- Variables,
- User inputs
- Caches etc.
YOU CAN LISTEN THESE STREAMS AND REACT ACCORDINGLY
Can use my regular mapping, filtering?
YES
RX Library provides amazing toolbox of functions to combine,
create and filter those streams
RX uses functional magic too! =>
- A stream can be used as an input to another one
- Multiple streams can be used as inputs to another stream
- Streams can be merged
- Streams can be filtered
- Data values in a particular stream can be mapped from one stream to another
What is at the center of Reactive
Programming
STREAMS
Clicking on a button stream
Streams
A stream is a sequence of ongoing events
ordered in time.
It can emit 3 things =>
- Value (of some type)
- Error
- Completed signal
Consider that the “completed” takes place, for instance, when the current window or
view containing that button is closed
Streams
We capture these emitted values
asynchronously => How? =>
- A function which will invoke after the value is emitted
- A function which will invoke after an error is emitted
- A function which will invoke after completed is emitted
Listening a stream is called => SUBSCRIPTION / SUBSCRIBING
Sometimes last 2 can be omitted. Only value emission is taken into account.
• Functions we are defining are called OBSERVERS.
• Stream is being observed by observers. Therefore it is the subject. That’s
why we call it OBSERVABLE
Streams
--a---b-c---d---X---|->
a, b, c, d are emitted values
X is an error
| is the 'completed' signal
---> is the timeline
Streams
clickStream: ---c----c--c----c------c-->
vvvvv map(c becomes 1) vvvv
---1----1--1----1------1-->
vvvvvvvvv scan(+) vvvvvvvvv
counterStream: ---1----2--3----4------5-->
Each stream has many functions attached to it, such as map, filter, scan, etc. When you
call one of these functions, such as clickStream.map(f), it returns a new stream based
on the click stream.
- Original stream is not modified. It is called immutability.
- Non modified streams allows us to chain functions =>
clickStream.map(mapFn).scan(addFn)
Stream example
• Lets make a stream of “double click” events. Or lets make “triple click”
events!
• Imagine how we would do that in a traditional imperative and stateful
way.
REACTIVE PROGRAMMING filters the implementation to 4 lines of code =>
- Grey boxes are functions
transforming one stream into
another.
- We can then subscribe ("listen")
to it to react accordingly how we
wish
* We can apply the same
operations on different kinds of
streams, on a stream of API
responses
Why should we consider Reactive Programming
• Raises the level of abstraction
Focus on business logic, don’t think about implementation details
Thinking in RP with examples =>
Rx library family is available for => (.NET, Java, Scala, Clojure, JavaScript, Ruby, Python, C++,
Objective-C/Cocoa, Groovy, etc)
http://reactivex.io/languages.html
Through our presentation we will use RxJS
Implementing “Who to follow”
suggestions box
RX Example
1. Doing the request
2. Getting the request
3. Rendering the response
--a------|->
Where a is the string 'https://api.github.com/users'
RX Example
• To create such stream with a single value is
simple in RX. Official terminology for a stream
is => Observable.
RX Example
RX Example
Rx.Observable.create => Creates your own custom stream by explicitly
informing each observer (or in other words, a "subscriber") about data
events (onNext()) or errors (onError()). What we did was just wrap that
jQuery Ajax Promise.
PROMISE IS AN OBSERVABLE => YES! OBSERVABLE IS PROMISE ++
RX Example
In RX we can easily convert Promise to an observable by using
Rx.Observable.fromPromise(promise)
What we have created is stream of streams (metastream)
Reactive programming
RX Example
• What we just wanted was a simple stream of users (an Array each time). A
. Not a stream of streams.
requestStream: --a-----b--c------------|->
responseStream: -----A--------B-----C---|->
(lowercase is a request, uppercase is
its response)
RX Example
RX Example
Refresh Button
But something broke => A request doesn’t happen anymore on startup
SOLUTION => Merging requestOnRefreshStream with startupRequestStream
RX Example
stream A: ---a--------e-----o----->
stream B: -----B---C-----D-------->
vvvvvvvvv merge vvvvvvvvv
---a-B---C--e--D--o----->
RX Example
There is a cleaner way of writing it =>
Even cleaner
RX Example
Even more cleaner
Look at startWith from rxjs docs
RX Example
We want ‘on Refresh’ => ‘Clear suggestions’
Modelling Suggestions
RX Example
When rendering, we interpret null as “no-data”, hence hiding its UI element
RX Example
We can empty suggestions during startup
RX Example
Closing suggestions and using cached responses
This DOES NOT WORK
RX Example
Let’s think about it
In RX there is combineLatest operator
RX Example

More Related Content

PPTX
Reactive programming with rx java
PPTX
Reactive programming intro
PDF
Reactive programming and RxJS
PDF
Reactive: Programming -> Systems -> Architecture
PDF
Introduction to reactive programming
PPTX
Reactive programming
PPTX
Functional reactive programming
PDF
Reactive programming - Observable
Reactive programming with rx java
Reactive programming intro
Reactive programming and RxJS
Reactive: Programming -> Systems -> Architecture
Introduction to reactive programming
Reactive programming
Functional reactive programming
Reactive programming - Observable

What's hot (20)

PPTX
Project Reactor By Example
PDF
Reactive java - Reactive Programming + RxJava
PPTX
Reactive programming
PDF
Demystifying Reactive Programming
PDF
Declarative Concurrency with Reactive Programming
PPTX
Reactive Programming In Java Using: Project Reactor
PDF
Understanding Reactive Programming
PPTX
Introduction to Reactive programming
PPTX
stigbot_beta
PDF
Take a Look at Akka+Java (English version)
PDF
Introduction to Akka Streams
PPTX
Quick Tour On Zeppelin
PPTX
An eclipse client server architecture with asynchronous messaging
PPTX
Architectural Patterns - Interactive and Event Handling Patterns
PDF
Conjunctive queries
PPTX
Mini-Training: Let's have a rest
PDF
Introduction to Functional Reactive Programming
PPTX
Mule esb usecase
PPTX
Java 8 New features
PPTX
Project Reactor By Example
Reactive java - Reactive Programming + RxJava
Reactive programming
Demystifying Reactive Programming
Declarative Concurrency with Reactive Programming
Reactive Programming In Java Using: Project Reactor
Understanding Reactive Programming
Introduction to Reactive programming
stigbot_beta
Take a Look at Akka+Java (English version)
Introduction to Akka Streams
Quick Tour On Zeppelin
An eclipse client server architecture with asynchronous messaging
Architectural Patterns - Interactive and Event Handling Patterns
Conjunctive queries
Mini-Training: Let's have a rest
Introduction to Functional Reactive Programming
Mule esb usecase
Java 8 New features
Ad

Similar to Reactive programming (20)

PPTX
PPTX
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
PDF
Reactive Programming
PDF
Reactive systems
PDF
I have a stream - Insights in Reactive Programming - Jan Carsten Lohmuller - ...
PPTX
Reactive Programming with RxJS
PDF
Moving towards Reactive Programming
PDF
DZone_RC_RxJS
PDF
My Gentle Introduction to RxJS
PPTX
Functional Reactive Programming with RxJS
PDF
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...
PPTX
Reactive Programming in Java 8 with Rx-Java
PDF
RxJS - The Reactive Extensions for JavaScript
PDF
Reactive Programming
PPTX
Luis Atencio on RxJS
PDF
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
PDF
Reactive Programming for a demanding world: building event-driven and respons...
PPTX
Mini training - Reactive Extensions (Rx)
PPTX
Solve it Differently with Reactive Programming
PPTX
Real world functional reactive programming
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Reactive Programming
Reactive systems
I have a stream - Insights in Reactive Programming - Jan Carsten Lohmuller - ...
Reactive Programming with RxJS
Moving towards Reactive Programming
DZone_RC_RxJS
My Gentle Introduction to RxJS
Functional Reactive Programming with RxJS
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...
Reactive Programming in Java 8 with Rx-Java
RxJS - The Reactive Extensions for JavaScript
Reactive Programming
Luis Atencio on RxJS
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming for a demanding world: building event-driven and respons...
Mini training - Reactive Extensions (Rx)
Solve it Differently with Reactive Programming
Real world functional reactive programming
Ad

Recently uploaded (20)

PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Introduction to Artificial Intelligence
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPT
Introduction Database Management System for Course Database
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
System and Network Administration Chapter 2
PDF
AI in Product Development-omnex systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
ISO 45001 Occupational Health and Safety Management System
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Introduction to Artificial Intelligence
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Operating system designcfffgfgggggggvggggggggg
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ManageIQ - Sprint 268 Review - Slide Deck
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
L1 - Introduction to python Backend.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Introduction Database Management System for Course Database
Softaken Excel to vCard Converter Software.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
System and Network Administration Chapter 2
AI in Product Development-omnex systems
How to Migrate SBCGlobal Email to Yahoo Easily
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administraation Chapter 3
Design an Analysis of Algorithms I-SECS-1021-03
ISO 45001 Occupational Health and Safety Management System

Reactive programming

  • 2. Programming Types Hardest part while learning Reactive Programming => THINKING IN REACTIVE Programming Types - Imperative (Stateful) - Declarative - Functional (Stateless) - Reactive
  • 3. Programming Types IMPERATIVE Imperative programming is a programming paradigm that uses statements that change a program’s state.
  • 4. Programming Types DECLARATIVE Declarative programming is a programming paradigm … that expresses the logic of a computation without describing its control flow.
  • 5. Programming Types REACTIVE - Wikipedia => it is like a description in a CS book which is generic and theoretical - Reactive manifesto => it is so generic for a developer with dirty hands - Stackoverlow => Look at stackoverflow and never look back to reactive programming again. Morale killing explanations, hard and most advanced stuff without explaining its core. Reactive programming is programming with asynchronous data streams Nothing new just made easier! It is like dealing with event streams such as => - Event buses - Click events Streams are cheap, anything can be a stream: - Variables, - User inputs - Caches etc. YOU CAN LISTEN THESE STREAMS AND REACT ACCORDINGLY
  • 6. Can use my regular mapping, filtering? YES RX Library provides amazing toolbox of functions to combine, create and filter those streams RX uses functional magic too! => - A stream can be used as an input to another one - Multiple streams can be used as inputs to another stream - Streams can be merged - Streams can be filtered - Data values in a particular stream can be mapped from one stream to another
  • 7. What is at the center of Reactive Programming STREAMS Clicking on a button stream
  • 8. Streams A stream is a sequence of ongoing events ordered in time. It can emit 3 things => - Value (of some type) - Error - Completed signal Consider that the “completed” takes place, for instance, when the current window or view containing that button is closed
  • 9. Streams We capture these emitted values asynchronously => How? => - A function which will invoke after the value is emitted - A function which will invoke after an error is emitted - A function which will invoke after completed is emitted Listening a stream is called => SUBSCRIPTION / SUBSCRIBING Sometimes last 2 can be omitted. Only value emission is taken into account. • Functions we are defining are called OBSERVERS. • Stream is being observed by observers. Therefore it is the subject. That’s why we call it OBSERVABLE
  • 10. Streams --a---b-c---d---X---|-> a, b, c, d are emitted values X is an error | is the 'completed' signal ---> is the timeline
  • 11. Streams clickStream: ---c----c--c----c------c--> vvvvv map(c becomes 1) vvvv ---1----1--1----1------1--> vvvvvvvvv scan(+) vvvvvvvvv counterStream: ---1----2--3----4------5--> Each stream has many functions attached to it, such as map, filter, scan, etc. When you call one of these functions, such as clickStream.map(f), it returns a new stream based on the click stream. - Original stream is not modified. It is called immutability. - Non modified streams allows us to chain functions => clickStream.map(mapFn).scan(addFn)
  • 12. Stream example • Lets make a stream of “double click” events. Or lets make “triple click” events! • Imagine how we would do that in a traditional imperative and stateful way. REACTIVE PROGRAMMING filters the implementation to 4 lines of code =>
  • 13. - Grey boxes are functions transforming one stream into another. - We can then subscribe ("listen") to it to react accordingly how we wish * We can apply the same operations on different kinds of streams, on a stream of API responses
  • 14. Why should we consider Reactive Programming • Raises the level of abstraction Focus on business logic, don’t think about implementation details Thinking in RP with examples => Rx library family is available for => (.NET, Java, Scala, Clojure, JavaScript, Ruby, Python, C++, Objective-C/Cocoa, Groovy, etc) http://reactivex.io/languages.html Through our presentation we will use RxJS
  • 15. Implementing “Who to follow” suggestions box
  • 16. RX Example 1. Doing the request 2. Getting the request 3. Rendering the response --a------|-> Where a is the string 'https://api.github.com/users'
  • 17. RX Example • To create such stream with a single value is simple in RX. Official terminology for a stream is => Observable.
  • 19. RX Example Rx.Observable.create => Creates your own custom stream by explicitly informing each observer (or in other words, a "subscriber") about data events (onNext()) or errors (onError()). What we did was just wrap that jQuery Ajax Promise. PROMISE IS AN OBSERVABLE => YES! OBSERVABLE IS PROMISE ++
  • 20. RX Example In RX we can easily convert Promise to an observable by using Rx.Observable.fromPromise(promise) What we have created is stream of streams (metastream)
  • 22. RX Example • What we just wanted was a simple stream of users (an Array each time). A . Not a stream of streams. requestStream: --a-----b--c------------|-> responseStream: -----A--------B-----C---|-> (lowercase is a request, uppercase is its response)
  • 24. RX Example Refresh Button But something broke => A request doesn’t happen anymore on startup SOLUTION => Merging requestOnRefreshStream with startupRequestStream
  • 25. RX Example stream A: ---a--------e-----o-----> stream B: -----B---C-----D--------> vvvvvvvvv merge vvvvvvvvv ---a-B---C--e--D--o----->
  • 26. RX Example There is a cleaner way of writing it => Even cleaner
  • 27. RX Example Even more cleaner Look at startWith from rxjs docs
  • 28. RX Example We want ‘on Refresh’ => ‘Clear suggestions’ Modelling Suggestions
  • 29. RX Example When rendering, we interpret null as “no-data”, hence hiding its UI element
  • 30. RX Example We can empty suggestions during startup
  • 31. RX Example Closing suggestions and using cached responses This DOES NOT WORK
  • 32. RX Example Let’s think about it In RX there is combineLatest operator

Editor's Notes

  • #12: The map(f) function replaces (into the new stream) each emitted value according to a function f you provide. In our case, we mapped to the number 1 on each click. The scan(g) function aggregates all previous values on the stream, producing value x = g(accumulated, current), where g was simply the add function in this example. Then, counterStream emits the total number of clicks whenever a click happens.