SlideShare a Scribd company logo
1 of 44
Download to read offline
ReactiveX
An API for asynchronous programming
with observable streams
What is it all about?
What is ReactiveX (Rx)?
[2, 15, 13, 46, 7]
filter(x => x < 10)
[2, 7]
What is ReactiveX (Rx)?
● Python
● Javascript
● PHP
● etc...
● Underscore.js
● Lodash.js
● LINQ (C#)
● Guava (Java)
● etc..
What is ReactiveX (Rx)?
x: 121
Y: 250
x: 659
Y: 37
x: 55
Y: 498
x: 984
Y: 35
x: 121
Y: 43
x: 165
Y: 268
x: 435
Y: 316
time
filter(condition)
x: 659
Y: 37
x: 984
Y: 35
x: 121
Y: 43 time
Think of it as an
asynchronous
immutable array.
Streams!
Observables
Observables vs Promises
Multiple valuesSingle value
Temporal /
Asynchronous /
Push
Spatial /
Synchronous /
Pull
Observable<T> getData()
Iterable<T> getData()T getData()
Promise<T> getData()
Where it can be useful?
● Everywhere
● Frontend
○ UI events, API responses, etc
● Backend
○ Concurrency, services communication, etc
● Available for:
○ Java, JavaScript, C#, C#(Unity), Scala, Clojure, C++, Lua, Ruby, Python, Go, Groovy, JRuby,
Kotlin, Swift, PHP, Elixir, Dart, Netty, Android, Cocoa
How to start?
Building blocks
● Observer pattern
● Iterator pattern
● Functional programming
Observer Pattern
Iterator Pattern
Functional Programming
● Immutability
● Pure functions
● High-order functions
● Currying
● Composition
Main Concepts
● Observable
● Subject
● Operators
● Scheduler*
Observables
A representation of any
set of values over
any amount of time.
Observable
const source = fromEvent(document, 'click');
const myObservable = fromEvent(button, 'click');
const isOnline = fromEvent(window, 'online');
const onFocus = fromEvent(input, 'focus');
const keyPressed = fromEvent(input, 'keypress');
Observable
const arraySource = from([1, 2, 3, 4, 5]);
const promise = new Promise(resolve => resolve('Hello!'));
const promiseSource = from(promise);
const source = from('Hello World');
Observable
const source = of(1, 2, 3, 4, 5);
const source = of({ name: 'Brian' }, [1, 2, 3], function
hello() { return 'Hello'; });
Observable
const foo = new Observable(observer => {
observer.next(42);
observer.next(100);
observer.next(200);
setTimeout(() => {
observer.next(300); // happens asynchronously
}, 1000);
});
Observable
● An Observable emits items or sends notifications to its observers by calling
the observers’ methods.
● An observer subscribes to an Observable.
next()
attach()
Observable
const foo = new Observable(observer => {
observer.next(42);
observer.next(100);
observer.next(200);
setTimeout(() => {
observer.next(300); // happens asynchronously
}, 1000);
});
Observable
const observer = {
// on each new emitted value by the observable
next: value => {},
// if some error occurs inside the observable
error: error => {},
// the observable has ran out of items
complete: () => {},
};
const observer1 = {
next: value => console.log(`[Observer 1]: Received ${value}!`),
error: error => console.log(`[Observer 1]: ${error}!`),
complete: () => console.log(`[Observer 1]: No more items! `),
};
foo.subscribe(observer1);
foo.subscribe(
value => console.log(`[Observer 2]: Received ${value}!`),
error => console.log(`[Observer 2]: ${error}!`),
);
foo.subscribe(value => console.log(`[Observer 3]: Received ${value}!`));
Cold
● The data is produced by the
Observable itself.
● It begins to emit items only after
the observer subscribes to it.
● Each observer (subscriber) gets
its own unique set of items.
Hot
● The data is produced outside
the Observable itself.
● It may begin emitting items as
soon as it is created.
● The emitted items are shared
between the subscribers
(multicasting).
vs
https://stackblitz.com/edit/hot-vs-cold
Subject
Observable ObserverSubject
● Multicast observable (plain observables are unicast)
○ It manages an internal list of observers
● It implements the observer interface
○ next(), error() and complete()
● Useful for
○ Multicast items to observers
○ “Convert” plain unicast observable to multicast
Subject
https://stackblitz.com/edit/learn-subjects
Operators
● Composition + Declarative = The power of ReactiveX!
● It allows you to transform, combine, manipulate, and work with the
sequences of emitted items.
● .pipe() method.
● You can create your own custom operators!
Operators
Operators
const source$ = range(0, 10);
source$.pipe(
filter(x => x % 2 === 0),
map(x => x + x),
scan((acc, x) => acc + x, 0)
)
.subscribe(x => console.log(x)); // [0, 4, 12, 24, 40]
Operators
● Creation
○ create, ajax, empty, from, fromEvent, interval, of, range, timer, etc.
● Combination
○ combineLatest, concat, merge, pairwise, startWith, zip, etc.
● Conditional
○ iif, defaultIfEmpty, every, sequenceequal.
● Error Handling
○ catchError, retry, retryWhen.
Operators
● Filtering
○ debounceTime, distinctUntilChanged, filter, find, first, last, skip, take, takeUntil, etc.
● Multicasting
○ multicast, publish, share, shareReplay
● Transformation
○ buffer, bufferCount, bufferWhen, groupBy, map, flatMap, partition, pluck, scan, switchMap,
windowTime, etc
● Utility
○ tap, delay, finally, repeat, timeInterval, timeout, toPromise, etc
It’s not easy. It will
take some time.
Control Flow vs Data Flow
series
branchesbatch
on demand!
concurrence
async
Examples
Autocomplete
https://stackblitz.com/edit/ex-autocomplete
Bonus: Scheduler!
Scheduler
● Multithreading!
○ By default, observables, its operators chain and observers run in the same thread.
● Defines the execution context
○ Where and when the task is executed.
● May vary on the implementation
References
● 2 minute introduction to Rx
● ReactiveX site
● Learn RxJS
● Hot vs Cold Observables
● RxJS docs
Thanks!
Contact:
Gabriel Araujo
Invillia
151 Padre Duarte
Araraquara, SP 14800-360
contato@gabrielaraujo.dev
gabrielaraujo.dev
@gabrielfeear

More Related Content

What's hot

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
 
Меняем javascript с помощью javascript
Меняем javascript с помощью javascriptМеняем javascript с помощью javascript
Меняем javascript с помощью javascriptPavel Volokitin
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp
 
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsПродвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsFDConf
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIIAjit Nayak
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojureRoy Rutto
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monadsrkaippully
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3Simon Su
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020InfluxData
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Steffen Wenz
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoKim Phillips
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopSages
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in DepthC4Media
 

What's hot (20)

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Rcpp11 useR2014
Rcpp11 useR2014Rcpp11 useR2014
Rcpp11 useR2014
 
ts
tsts
ts
 
JVM Architecture - Java
JVM Architecture - JavaJVM Architecture - Java
JVM Architecture - Java
 
Меняем javascript с помощью javascript
Меняем javascript с помощью javascriptМеняем javascript с помощью javascript
Меняем javascript с помощью javascript
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223
 
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsПродвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
 
Formal methods
Formal methods Formal methods
Formal methods
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt III
 
Brief intro to clojure
Brief intro to clojureBrief intro to clojure
Brief intro to clojure
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 
ECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScriptECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScript
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 

Similar to Reactive x

rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simplerAlexander Mostovenko
 
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...GeeksLab Odessa
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架jeffz
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptViliam Elischer
 
Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensionsOleksandr Zhevzhyk
 
Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSAdam L Barrett
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 
GDG DevFest 2015 - Reactive approach for slowpokes
GDG DevFest 2015 - Reactive approach for slowpokesGDG DevFest 2015 - Reactive approach for slowpokes
GDG DevFest 2015 - Reactive approach for slowpokesSergey Tarasevich
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)jeffz
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaWiem Zine Elabidine
 

Similar to Reactive x (20)

rx.js make async programming simpler
rx.js make async programming simplerrx.js make async programming simpler
rx.js make async programming simpler
 
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScript
 
Rx – reactive extensions
Rx – reactive extensionsRx – reactive extensions
Rx – reactive extensions
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
Rxjs kyivjs 2015
Rxjs kyivjs 2015Rxjs kyivjs 2015
Rxjs kyivjs 2015
 
Understanding reactive programming with microsoft reactive extensions
Understanding reactive programming  with microsoft reactive extensionsUnderstanding reactive programming  with microsoft reactive extensions
Understanding reactive programming with microsoft reactive extensions
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
GDG DevFest 2015 - Reactive approach for slowpokes
GDG DevFest 2015 - Reactive approach for slowpokesGDG DevFest 2015 - Reactive approach for slowpokes
GDG DevFest 2015 - Reactive approach for slowpokes
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in Scala
 

Recently uploaded

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Recently uploaded (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Reactive x

  • 1. ReactiveX An API for asynchronous programming with observable streams
  • 2. What is it all about?
  • 3. What is ReactiveX (Rx)? [2, 15, 13, 46, 7] filter(x => x < 10) [2, 7]
  • 4. What is ReactiveX (Rx)? ● Python ● Javascript ● PHP ● etc... ● Underscore.js ● Lodash.js ● LINQ (C#) ● Guava (Java) ● etc..
  • 5. What is ReactiveX (Rx)? x: 121 Y: 250 x: 659 Y: 37 x: 55 Y: 498 x: 984 Y: 35 x: 121 Y: 43 x: 165 Y: 268 x: 435 Y: 316 time filter(condition) x: 659 Y: 37 x: 984 Y: 35 x: 121 Y: 43 time
  • 6. Think of it as an asynchronous immutable array. Streams!
  • 8. Observables vs Promises Multiple valuesSingle value Temporal / Asynchronous / Push Spatial / Synchronous / Pull Observable<T> getData() Iterable<T> getData()T getData() Promise<T> getData()
  • 9. Where it can be useful? ● Everywhere ● Frontend ○ UI events, API responses, etc ● Backend ○ Concurrency, services communication, etc ● Available for: ○ Java, JavaScript, C#, C#(Unity), Scala, Clojure, C++, Lua, Ruby, Python, Go, Groovy, JRuby, Kotlin, Swift, PHP, Elixir, Dart, Netty, Android, Cocoa
  • 11. Building blocks ● Observer pattern ● Iterator pattern ● Functional programming
  • 14. Functional Programming ● Immutability ● Pure functions ● High-order functions ● Currying ● Composition
  • 15. Main Concepts ● Observable ● Subject ● Operators ● Scheduler*
  • 17. A representation of any set of values over any amount of time.
  • 18. Observable const source = fromEvent(document, 'click'); const myObservable = fromEvent(button, 'click'); const isOnline = fromEvent(window, 'online'); const onFocus = fromEvent(input, 'focus'); const keyPressed = fromEvent(input, 'keypress');
  • 19. Observable const arraySource = from([1, 2, 3, 4, 5]); const promise = new Promise(resolve => resolve('Hello!')); const promiseSource = from(promise); const source = from('Hello World');
  • 20. Observable const source = of(1, 2, 3, 4, 5); const source = of({ name: 'Brian' }, [1, 2, 3], function hello() { return 'Hello'; });
  • 21. Observable const foo = new Observable(observer => { observer.next(42); observer.next(100); observer.next(200); setTimeout(() => { observer.next(300); // happens asynchronously }, 1000); });
  • 22. Observable ● An Observable emits items or sends notifications to its observers by calling the observers’ methods. ● An observer subscribes to an Observable. next() attach()
  • 23. Observable const foo = new Observable(observer => { observer.next(42); observer.next(100); observer.next(200); setTimeout(() => { observer.next(300); // happens asynchronously }, 1000); });
  • 24. Observable const observer = { // on each new emitted value by the observable next: value => {}, // if some error occurs inside the observable error: error => {}, // the observable has ran out of items complete: () => {}, };
  • 25. const observer1 = { next: value => console.log(`[Observer 1]: Received ${value}!`), error: error => console.log(`[Observer 1]: ${error}!`), complete: () => console.log(`[Observer 1]: No more items! `), }; foo.subscribe(observer1); foo.subscribe( value => console.log(`[Observer 2]: Received ${value}!`), error => console.log(`[Observer 2]: ${error}!`), ); foo.subscribe(value => console.log(`[Observer 3]: Received ${value}!`));
  • 26. Cold ● The data is produced by the Observable itself. ● It begins to emit items only after the observer subscribes to it. ● Each observer (subscriber) gets its own unique set of items. Hot ● The data is produced outside the Observable itself. ● It may begin emitting items as soon as it is created. ● The emitted items are shared between the subscribers (multicasting). vs https://stackblitz.com/edit/hot-vs-cold
  • 29. ● Multicast observable (plain observables are unicast) ○ It manages an internal list of observers ● It implements the observer interface ○ next(), error() and complete() ● Useful for ○ Multicast items to observers ○ “Convert” plain unicast observable to multicast Subject https://stackblitz.com/edit/learn-subjects
  • 31. ● Composition + Declarative = The power of ReactiveX! ● It allows you to transform, combine, manipulate, and work with the sequences of emitted items. ● .pipe() method. ● You can create your own custom operators! Operators
  • 32.
  • 33. Operators const source$ = range(0, 10); source$.pipe( filter(x => x % 2 === 0), map(x => x + x), scan((acc, x) => acc + x, 0) ) .subscribe(x => console.log(x)); // [0, 4, 12, 24, 40]
  • 34. Operators ● Creation ○ create, ajax, empty, from, fromEvent, interval, of, range, timer, etc. ● Combination ○ combineLatest, concat, merge, pairwise, startWith, zip, etc. ● Conditional ○ iif, defaultIfEmpty, every, sequenceequal. ● Error Handling ○ catchError, retry, retryWhen.
  • 35. Operators ● Filtering ○ debounceTime, distinctUntilChanged, filter, find, first, last, skip, take, takeUntil, etc. ● Multicasting ○ multicast, publish, share, shareReplay ● Transformation ○ buffer, bufferCount, bufferWhen, groupBy, map, flatMap, partition, pluck, scan, switchMap, windowTime, etc ● Utility ○ tap, delay, finally, repeat, timeInterval, timeout, toPromise, etc
  • 36.
  • 37. It’s not easy. It will take some time.
  • 38. Control Flow vs Data Flow series branchesbatch on demand! concurrence async
  • 42. Scheduler ● Multithreading! ○ By default, observables, its operators chain and observers run in the same thread. ● Defines the execution context ○ Where and when the task is executed. ● May vary on the implementation
  • 43. References ● 2 minute introduction to Rx ● ReactiveX site ● Learn RxJS ● Hot vs Cold Observables ● RxJS docs
  • 44. Thanks! Contact: Gabriel Araujo Invillia 151 Padre Duarte Araraquara, SP 14800-360 contato@gabrielaraujo.dev gabrielaraujo.dev @gabrielfeear