SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
RxSwift: Subjects & Operators
Saravudh Sinsomros
30.03.22
What is RxSwift
Subjects
○ PublishSubjects
○ BehaviorSubjects
○ ReplaySubjects
○ AsyncSubjects
Combining Operators
○ CombineLatest
○ Merge
○ Zip
Agenda
What is RxSwift
RxSwift, simplifies
developing asynchronous
programs by allowing
your code to react to new
data and process it in
sequential, isolated
manner.
raywenderlich.com
Observer 1
Observer 2
Observer 3
Observable<Int>
2, 3, 5, 7, 11, 13, 17 |
2, 3, 5, 7, 11, 13, 17 |
2, 3, 5, 7, 11, 13, 17 |
Operator
Subjects
PublishSubjects
https://reactivex.io
Starts empty and only
emits new elements to
subscribers
Coding
subject.onNext("Green")
let subscriptionTwo = subject
.subscribe(onNext: { item in
print("subscriptionTwo: (item)")
})
subscriptionTwo.disposed(by: disposeBag)
subject.onNext("Blue")
subject.onNext("Red")
subscriptionOne: Red
subscriptionOne: Green
subscriptionOne: Blue
subscriptionTwo: Blue
PublishSubjects
let subscriptionOne = subject
.subscribe(onNext: { item in
print("subscriptionOne: (item)")
})
subscriptionOne.disposed(by: disposeBag)
let subject = PublishSubject<String>()
BehaviorSubjects
https://reactivex.io
Starts with an initial
value and replays it or
the latest element to new
subscribers
Coding
let subject = BehaviorSubject<String>(value: "Purple")
subject.onNext("Red")
subject.onNext(“Green")
subject.onNext("Blue")
let subscriptionTwo = subject
.subscribe(onNext: { item in
print("subscriptionTwo: (item)")
})
subscriptionTwo.disposed(by: disposeBag)
subscriptionOne: Purple
subscriptionOne: Red
subscriptionOne: Green
subscriptionTwo: Green
subscriptionOne: Blue
subscriptionTwo: Blue
BehaviorSubjects
let subscriptionOne = subject
.subscribe(onNext: { item in
print("subscriptionOne: (item)n")
})
subscriptionOne.disposed(by: disposeBag)
ReplaySubjects
https://reactivex.io
Initialized with a buffer
size and will maintain a
buffer of elements up to
that size and replay it to
new subscribers
Coding
let subject = ReplaySubject<String>.create(bufferSize: 3)
subject.onNext("Red")
subject.onNext("Green")
let subscriptionTwo = subject
.subscribe(onNext: { item in
print("subscriptionTwo: (item)n")
})
subscriptionTwo.disposed(by: disposeBag)
subject.onNext("Blue")
subscriptionOne: Red
subscriptionOne: Green
subscriptionTwo: Red
subscriptionTwo: Green
subscriptionOne: Blue
subscriptionTwo: Blue
ReplaySubjects
let subscriptionOne = subject
.subscribe(onNext: { item in
print("subscriptionOne: (item)n")
})
subscriptionOne.disposed(by: disposeBag)
AsyncSubjects
https://reactivex.io
Emits only the last value
Coding
let subject = AsyncSubject<String>()
subject.onNext("Red")
let subscriptionTwo = subject
.subscribe(onNext: { item in
print("subscriptionTwo: (item)n")
})
subscriptionTwo.disposed(by: disposeBag)
subject.onNext("Green")
subject.onNext("Blue")
subject.onCompleted()
subscriptionOne: Blue
subscriptionTwo: Blue
AsyncSubjects
let subscriptionOne = subject
.subscribe(onNext: { item in
print("subscriptionOne: (item)n")
})
subscriptionOne.disposed(by: disposeBag)
Combining Operators
Merge
combine multiple
Observables into one by
merging their emissions
https://reactivex.io
Coding
let input1 = PublishSubject<String>()
let input2 = PublishSubject<String>()
let output = Observable.of(input1.asObservable(),
input2.asObservable()).merge()
output.subscribe(onNext: { item in
print("(item)n")
}).disposed(by: disposeBag)
input1.onNext("20")
input1.onNext("40")
input1.onNext("60")
input2.onNext("1")
input1.onNext("80")
input1.onNext("100")
input2.onNext("1")
20
40
60
1
80
100
1
Merge
CombineLatest
combine values from
several sequences
together
https://reactivex.io
Coding
let input1 = PublishSubject<String>()
let input2 = PublishSubject<String>()
let output = Observable.combineLatest(input1, input2, resultSelector: {
lastTop, lastBottom in
"((lastTop)(lastBottom))"
})
output.subscribe(onNext: { item in
print("combineLatest: (item)n")
}).disposed(by: disposeBag)
input1.onNext("1")
input2.onNext("A")
input1.onNext("2")
input2.onNext("B")
input2.onNext("C")
input2.onNext("D")
input1.onNext("3")
input1.onNext("4")
(1A)
(2A)
(2B)
(2C)
(2D)
(3D)
(4D)
CombineLatest
Zip
combine the emissions
of multiple Observables
together via a specified
function and emit single
items for each
combination based on
the results of this
function
https://reactivex.io
Coding
let input1 = PublishSubject<String>()
let input2 = PublishSubject<String>()
let output = Observable.zip(input1.asObservable(), input2.asObservable())
output.subscribe(onNext: { item1, item2 in
print("(item1)(item2)n")
}).disposed(by: disposeBag)
input1.onNext("1")
input2.onNext("A")
input1.onNext("2")
input2.onNext("B")
input2.onNext("C")
input2.onNext("D")
input1.onNext("3")
input1.onNext("4")
input1.onCompleted()
input2.onNext("E")
1A
2B
3C
4D
Zip
Discussion
“First, solve the problem.
Then, write the code.”
- John Johnson
UPCOMING MEETUP
Check out our event page
Stay tuned for whatʼs coming next!

Contenu connexe

Tendances

Climate data in r with the raster package
Climate data in r with the raster packageClimate data in r with the raster package
Climate data in r with the raster package
Alberto Labarga
 
Data management with ado
Data management with adoData management with ado
Data management with ado
Dinesh kumar
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
Bruce McPherson
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodb
Lee Theobald
 

Tendances (20)

最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと
 
Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4Synapse india dotnet development overloading operater part 4
Synapse india dotnet development overloading operater part 4
 
Fetch data from form
Fetch data from formFetch data from form
Fetch data from form
 
Getting your data in and out of elasticsearch: let me count the ways
Getting your data in and out of elasticsearch: let me count the waysGetting your data in and out of elasticsearch: let me count the ways
Getting your data in and out of elasticsearch: let me count the ways
 
Climate data in r with the raster package
Climate data in r with the raster packageClimate data in r with the raster package
Climate data in r with the raster package
 
Sse
SseSse
Sse
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
MongoDB.local DC 2018: Scaling Realtime Apps with Change Streams
MongoDB.local DC 2018: Scaling Realtime Apps with Change StreamsMongoDB.local DC 2018: Scaling Realtime Apps with Change Streams
MongoDB.local DC 2018: Scaling Realtime Apps with Change Streams
 
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
Meet the Experts: Visualize Your Time-Stamped Data Using the React-Based Gira...
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 
Data management with ado
Data management with adoData management with ado
Data management with ado
 
New text document
New text documentNew text document
New text document
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
Reactive Extensions (Rx)
Reactive Extensions (Rx)Reactive Extensions (Rx)
Reactive Extensions (Rx)
 
Streaming data to s3 using akka streams
Streaming data to s3 using akka streamsStreaming data to s3 using akka streams
Streaming data to s3 using akka streams
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodb
 
My Gentle Introduction to RxJS
My Gentle Introduction to RxJSMy Gentle Introduction to RxJS
My Gentle Introduction to RxJS
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 
W3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascriptW3C HTML5 KIG-How to write low garbage real-time javascript
W3C HTML5 KIG-How to write low garbage real-time javascript
 
Toy Model Overview
Toy Model OverviewToy Model Overview
Toy Model Overview
 

Similaire à RxSubject And Operators

Similaire à RxSubject And Operators (20)

Rx for Android & iOS by Harin Trivedi
Rx for Android & iOS  by Harin TrivediRx for Android & iOS  by Harin Trivedi
Rx for Android & iOS by Harin Trivedi
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
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
 
Reactive Programming no Android
Reactive Programming no AndroidReactive Programming no Android
Reactive Programming no Android
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
 
Demystifying Reactive Programming
Demystifying Reactive ProgrammingDemystifying Reactive Programming
Demystifying Reactive Programming
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2
 
RxJava for Android - GDG DevFest Ukraine 2015
RxJava for Android - GDG DevFest Ukraine 2015RxJava for Android - GDG DevFest Ukraine 2015
RxJava for Android - GDG DevFest Ukraine 2015
 
GKAC 2015 Apr. - RxAndroid
GKAC 2015 Apr. - RxAndroidGKAC 2015 Apr. - RxAndroid
GKAC 2015 Apr. - RxAndroid
 
The Ring programming language version 1.9 book - Part 90 of 210
The Ring programming language version 1.9 book - Part 90 of 210The Ring programming language version 1.9 book - Part 90 of 210
The Ring programming language version 1.9 book - Part 90 of 210
 
Writing Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepWriting Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeep
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
 
Saving lives with rx java
Saving lives with rx javaSaving lives with rx java
Saving lives with rx java
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 
Rxandroid
RxandroidRxandroid
Rxandroid
 
RxAndroid
RxAndroidRxAndroid
RxAndroid
 
The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189
 
Reactive Programming with RxSwift
Reactive Programming with RxSwiftReactive Programming with RxSwift
Reactive Programming with RxSwift
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 

Plus de Seven Peaks Speaks

BKK Web: Working with SEO
BKK Web: Working with SEOBKK Web: Working with SEO
BKK Web: Working with SEO
Seven Peaks Speaks
 

Plus de Seven Peaks Speaks (20)

BKK Web: Working with SEO
BKK Web: Working with SEOBKK Web: Working with SEO
BKK Web: Working with SEO
 
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
 
Seven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose Animation
 
Seven Peaks Speaks - Compose Navigation
Seven Peaks Speaks - Compose NavigationSeven Peaks Speaks - Compose Navigation
Seven Peaks Speaks - Compose Navigation
 
How to Get Better Performance Out of Your App
How to Get Better Performance Out of Your AppHow to Get Better Performance Out of Your App
How to Get Better Performance Out of Your App
 
Concurrency in Swift
Concurrency in SwiftConcurrency in Swift
Concurrency in Swift
 
DevSecOps on Azure
DevSecOps on AzureDevSecOps on Azure
DevSecOps on Azure
 
Secure Development of Azure Function
Secure Development of Azure FunctionSecure Development of Azure Function
Secure Development of Azure Function
 
Develop Security & Compliances in Azure
Develop Security & Compliances in AzureDevelop Security & Compliances in Azure
Develop Security & Compliances in Azure
 
Effective Lists Management
Effective Lists ManagementEffective Lists Management
Effective Lists Management
 
Layout Preview Tooling
Layout Preview ToolingLayout Preview Tooling
Layout Preview Tooling
 
Background Processing With Work Manager
Background Processing With Work ManagerBackground Processing With Work Manager
Background Processing With Work Manager
 
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
Delivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing PyramidDelivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing Pyramid
 
React context
React context  React context
React context
 
Getting hooked on performance and clean code
Getting hooked on performance and clean codeGetting hooked on performance and clean code
Getting hooked on performance and clean code
 
Establishing secure Biometric authentication in Android
Establishing secure Biometric authentication in AndroidEstablishing secure Biometric authentication in Android
Establishing secure Biometric authentication in Android
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android application
 
Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

RxSubject And Operators

  • 1. RxSwift: Subjects & Operators Saravudh Sinsomros 30.03.22
  • 2. What is RxSwift Subjects ○ PublishSubjects ○ BehaviorSubjects ○ ReplaySubjects ○ AsyncSubjects Combining Operators ○ CombineLatest ○ Merge ○ Zip Agenda
  • 3. What is RxSwift RxSwift, simplifies developing asynchronous programs by allowing your code to react to new data and process it in sequential, isolated manner. raywenderlich.com Observer 1 Observer 2 Observer 3 Observable<Int> 2, 3, 5, 7, 11, 13, 17 | 2, 3, 5, 7, 11, 13, 17 | 2, 3, 5, 7, 11, 13, 17 | Operator
  • 5. PublishSubjects https://reactivex.io Starts empty and only emits new elements to subscribers
  • 6. Coding subject.onNext("Green") let subscriptionTwo = subject .subscribe(onNext: { item in print("subscriptionTwo: (item)") }) subscriptionTwo.disposed(by: disposeBag) subject.onNext("Blue") subject.onNext("Red") subscriptionOne: Red subscriptionOne: Green subscriptionOne: Blue subscriptionTwo: Blue PublishSubjects let subscriptionOne = subject .subscribe(onNext: { item in print("subscriptionOne: (item)") }) subscriptionOne.disposed(by: disposeBag) let subject = PublishSubject<String>()
  • 7. BehaviorSubjects https://reactivex.io Starts with an initial value and replays it or the latest element to new subscribers
  • 8. Coding let subject = BehaviorSubject<String>(value: "Purple") subject.onNext("Red") subject.onNext(“Green") subject.onNext("Blue") let subscriptionTwo = subject .subscribe(onNext: { item in print("subscriptionTwo: (item)") }) subscriptionTwo.disposed(by: disposeBag) subscriptionOne: Purple subscriptionOne: Red subscriptionOne: Green subscriptionTwo: Green subscriptionOne: Blue subscriptionTwo: Blue BehaviorSubjects let subscriptionOne = subject .subscribe(onNext: { item in print("subscriptionOne: (item)n") }) subscriptionOne.disposed(by: disposeBag)
  • 9. ReplaySubjects https://reactivex.io Initialized with a buffer size and will maintain a buffer of elements up to that size and replay it to new subscribers
  • 10. Coding let subject = ReplaySubject<String>.create(bufferSize: 3) subject.onNext("Red") subject.onNext("Green") let subscriptionTwo = subject .subscribe(onNext: { item in print("subscriptionTwo: (item)n") }) subscriptionTwo.disposed(by: disposeBag) subject.onNext("Blue") subscriptionOne: Red subscriptionOne: Green subscriptionTwo: Red subscriptionTwo: Green subscriptionOne: Blue subscriptionTwo: Blue ReplaySubjects let subscriptionOne = subject .subscribe(onNext: { item in print("subscriptionOne: (item)n") }) subscriptionOne.disposed(by: disposeBag)
  • 12. Coding let subject = AsyncSubject<String>() subject.onNext("Red") let subscriptionTwo = subject .subscribe(onNext: { item in print("subscriptionTwo: (item)n") }) subscriptionTwo.disposed(by: disposeBag) subject.onNext("Green") subject.onNext("Blue") subject.onCompleted() subscriptionOne: Blue subscriptionTwo: Blue AsyncSubjects let subscriptionOne = subject .subscribe(onNext: { item in print("subscriptionOne: (item)n") }) subscriptionOne.disposed(by: disposeBag)
  • 14. Merge combine multiple Observables into one by merging their emissions https://reactivex.io
  • 15. Coding let input1 = PublishSubject<String>() let input2 = PublishSubject<String>() let output = Observable.of(input1.asObservable(), input2.asObservable()).merge() output.subscribe(onNext: { item in print("(item)n") }).disposed(by: disposeBag) input1.onNext("20") input1.onNext("40") input1.onNext("60") input2.onNext("1") input1.onNext("80") input1.onNext("100") input2.onNext("1") 20 40 60 1 80 100 1 Merge
  • 16. CombineLatest combine values from several sequences together https://reactivex.io
  • 17. Coding let input1 = PublishSubject<String>() let input2 = PublishSubject<String>() let output = Observable.combineLatest(input1, input2, resultSelector: { lastTop, lastBottom in "((lastTop)(lastBottom))" }) output.subscribe(onNext: { item in print("combineLatest: (item)n") }).disposed(by: disposeBag) input1.onNext("1") input2.onNext("A") input1.onNext("2") input2.onNext("B") input2.onNext("C") input2.onNext("D") input1.onNext("3") input1.onNext("4") (1A) (2A) (2B) (2C) (2D) (3D) (4D) CombineLatest
  • 18. Zip combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function https://reactivex.io
  • 19. Coding let input1 = PublishSubject<String>() let input2 = PublishSubject<String>() let output = Observable.zip(input1.asObservable(), input2.asObservable()) output.subscribe(onNext: { item1, item2 in print("(item1)(item2)n") }).disposed(by: disposeBag) input1.onNext("1") input2.onNext("A") input1.onNext("2") input2.onNext("B") input2.onNext("C") input2.onNext("D") input1.onNext("3") input1.onNext("4") input1.onCompleted() input2.onNext("E") 1A 2B 3C 4D Zip
  • 21. “First, solve the problem. Then, write the code.” - John Johnson
  • 22. UPCOMING MEETUP Check out our event page Stay tuned for whatʼs coming next!