SlideShare a Scribd company logo
1 of 51
Download to read offline
COMBINE
A TOUR OF
VY-SHANE XIE
I build software things at WiseTime
https://vyshane.com
I'm @vyshane on
The Combine framework
provides a declarative Swift API
for processing values over time.

The Combine framework
provides a declarative Swift API
for processing values over time.

STREAMS
Publisher SubscriberOperator Subscriber
Functional Reactive Programming
FRP is a programming paradigm for asynchronous
stream processing using the building blocks of
functional programming (e.g. map, reduce, filter).
FRP
RxSwift
ReactiveSwift
Is not new in the Swift ecosystem
Combine
HOW IS COMBINE DIFFERENT?
COMBINE IS
A foundational  framework
Deeply integrated with SwiftUI
Closed source
Not available on Linux
https://forums.swift.org/t/will-swiftnio-adapt-to-the-new-combine-framework/25166/11
ONE MORE THING
REACTIVE STREAMS SPEC?
Enables JVM streaming libraries to interoperate
Provides a design for implementing back pressure
BACK
PRESSURE?
userIDs getProfile save
Slow IO
PRODUCER CONSUMERPROCESSOR CONSUMERuserIDs getProfile save
Slow IO
😰
Incoming rate higher than we can process
PRODUCER CONSUMERuserIDs save
Slow IO
getProfile
💥We're out of memory
PRODUCER CONSUMERuserIDs save
Slow IO
getProfile
On overflow
drop elements
Not Great!
😒
PRODUCER CONSUMERPROCESSOR CONSUMERgetProfile save
Slow IO
🚦 😎
Signal demand upstream
THIS IS BACK PRESSURE
userIDs
COMBINE IS
A low level  framework
Deeply integrated with SwiftUI
Closed source
Not available on Linux
The first Swift FRP library that has back pressure built in
KEY CONCEPTS
COMBINE
SUBSCRIBEROperator
3 MAIN CONCEPTS
Publisher Subscriber
PUBLISHER
Knows how to deliver a stream of values over time
Publisher
PUBLISHER
The stream may complete successfully
Publisher
PUBLISHER
Or fail with an error
Publisher
PUBLISHER
An infinite stream that never ends is legal
Publisher
PUBLISHER
A stream that completes without emitting anything is OK
Publisher
THE PUBLISHER PROTOCOL
A publisher declares an Output type as well as a Failure type
SOME BUILT-IN WAYS TO PUBLISH VALUES
SUBSCRIBER
‣ Requests values from a publisher
‣ Acts on values as it receives them
‣ Declares an Input type and a Failure type
SUBSCRIBING TO A PUBLISHER
A subscriber can subscribe to a publisher if:
‣ Its input type matches the output type of the publisher
‣ Its failure type matches that of the publisher
Publisher Subscriber
O
F
I
F
SUBSCRIBING TO A PUBLISHER
A subscriber can subscribe to a publisher if:
‣ Its input type matches the output type of the publisher
‣ Its failure type matches that of the publisher
TWO BUILT-IN SUBSCRIBERS
Assign Subscriber
Assigns elements it receives to an object property at a keypath
The assign(to:on:) operator creates an Assign subscriber
and subscribes it to the upstream publisher
Sink Subscriber
Accepts closures that receive values and completion events
Useful when writing tests
OPERATORS
Operate on streams and allow you to:
‣ Transform values
‣ Filter values
‣ Combine publishers together
‣ Manipulate timing
‣ Perform sequence and aggregation operations
Operators are instance methods on the Publisher protocol
Many operators subscribe to the upstream publisher
and return a publisher of their own
This allows you to compose them into pipelines
EXAMPLE: CALLING A WEB SERVICE
EXAMPLE: CALLING A WEB SERVICE
EXAMPLE: CALLING A WEB SERVICE
assign(to:on:) is a subscription operator,
returns an AnyCancellable on which you can call .cancel()
RETURN TYPES OF CHAINED OPERATIONS
TYPE-ERASING OPERATOR
Whew!
DEBUG OPERATORS
Combine ships with some handy operators that you can
insert into your pipelines to debug them:
‣ print(_:to:)
‣ breakpoint(receiveSubscription:receiveOutput:
receiveCompletion:)
‣ breakpointOnError()
‣ handleEvents(receiveSubscription:receiveOutput:
receiveCompletion:receiveCancel:receiveRequest:)
... all yuor operators
SUBSCRIPTION LIFECYCLE
COMBINE
PUBLISHER SUBSCRIPTION SUBSCRIBER
Subscribes
Creates Sends
Requests values
Emits value
Returns demand
Updates
demand
Emits value
Demand
fulfilled,
pauses
Returns demand
Requests values
Emits value
Updates
demand
Returns demand
No more
values Emits completion
Receives
demand
Stream ends
Publishers are lazy
(cold)
PUBLISHER SUBSCRIPTION SUBSCRIBER
Subscribes
Creates Sends
Requests values
Emits value
Returns demand
Receives
demand
Stream cancelled
Deallocated
EXAMPLE - DEALLOCATED SUBSCRIPTION
Times out, test fails
EXAMPLE - DEALLOCATED SUBSCRIPTION
CANCELLABLE
‣ Can be cancelled
‣ Can be stored/retained
SUPPORTED PLATFORMS
Same as SwiftUI
SUPPORTED PLATFORMS
Swift 5.1+
iOS 13.0+
macOS 10.15+
tvOS 13.0+
watchOS 6.0+
Mac Catalyst 13.0+
RESOURCES
‣ Using Combine web book (free):
https://heckj.github.io/swiftui-notes/
‣ Combine: Asynchronous Programming with Swift (ebook):
https://store.raywenderlich.com/products/combine-
asynchronous-programming-with-swift
‣ WWDC: Introducing Combine (video)
https://developer.apple.com/videos/play/wwdc2019/722/
‣ WWDC: Combine in Practice (video)
https://developer.apple.com/videos/play/wwdc2019/721/
ANY QUESTIONS?
THANKS FOR LISTENING

More Related Content

What's hot

Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
Pragnesh Vaghela
 

What's hot (20)

Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJS
 
RxJS Operators - Real World Use Cases (FULL VERSION)
RxJS Operators - Real World Use Cases (FULL VERSION)RxJS Operators - Real World Use Cases (FULL VERSION)
RxJS Operators - Real World Use Cases (FULL VERSION)
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
 
Get Started with ReactJS 18 Development Services_ New Features and Updates.pptx
Get Started with ReactJS 18 Development Services_ New Features and Updates.pptxGet Started with ReactJS 18 Development Services_ New Features and Updates.pptx
Get Started with ReactJS 18 Development Services_ New Features and Updates.pptx
 
React Hooks
React HooksReact Hooks
React Hooks
 
Service discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring CloudService discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring Cloud
 
Intro to Reactive Programming
Intro to Reactive ProgrammingIntro to Reactive Programming
Intro to Reactive Programming
 
Building resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with SpringBuilding resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with Spring
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
What is Swagger?
What is Swagger?What is Swagger?
What is Swagger?
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
React Hooks
React HooksReact Hooks
React Hooks
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 
iOS Modular Architecture with Tuist
iOS Modular Architecture with TuistiOS Modular Architecture with Tuist
iOS Modular Architecture with Tuist
 
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
 
Reactive Microservices with Spring 5: WebFlux
Reactive Microservices with Spring 5: WebFlux Reactive Microservices with Spring 5: WebFlux
Reactive Microservices with Spring 5: WebFlux
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)
 
learn what React JS is & why we should use React JS .
learn what React JS is & why we should use React JS .learn what React JS is & why we should use React JS .
learn what React JS is & why we should use React JS .
 
Reactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorReactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project Reactor
 

Similar to A Tour of Combine

Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
HostedbyConfluent
 

Similar to A Tour of Combine (20)

Devoxx 2018 - Pivotal and AxonIQ - Quickstart your event driven architecture
Devoxx 2018 -  Pivotal and AxonIQ - Quickstart your event driven architectureDevoxx 2018 -  Pivotal and AxonIQ - Quickstart your event driven architecture
Devoxx 2018 - Pivotal and AxonIQ - Quickstart your event driven architecture
 
Streaming the platform with Confluent (Apache Kafka)
Streaming the platform with Confluent (Apache Kafka)Streaming the platform with Confluent (Apache Kafka)
Streaming the platform with Confluent (Apache Kafka)
 
Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...
Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...
Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...
 
Manchester Expert Talks (April 2017) - Breaking Down Your Build: Architectura...
Manchester Expert Talks (April 2017) - Breaking Down Your Build: Architectura...Manchester Expert Talks (April 2017) - Breaking Down Your Build: Architectura...
Manchester Expert Talks (April 2017) - Breaking Down Your Build: Architectura...
 
Microservices Integration Patterns with Kafka
Microservices Integration Patterns with KafkaMicroservices Integration Patterns with Kafka
Microservices Integration Patterns with Kafka
 
Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
 
What's New in Confluent Platform 5.5
What's New in Confluent Platform 5.5What's New in Confluent Platform 5.5
What's New in Confluent Platform 5.5
 
Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...
Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...
Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...
 
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
 
Event streaming: A paradigm shift in enterprise software architecture
Event streaming: A paradigm shift in enterprise software architectureEvent streaming: A paradigm shift in enterprise software architecture
Event streaming: A paradigm shift in enterprise software architecture
 
Building event-driven (Micro)Services with Apache Kafka Ecosystem
Building event-driven (Micro)Services with Apache Kafka EcosystemBuilding event-driven (Micro)Services with Apache Kafka Ecosystem
Building event-driven (Micro)Services with Apache Kafka Ecosystem
 
Deep Dive on Serverless Stack
Deep Dive on Serverless StackDeep Dive on Serverless Stack
Deep Dive on Serverless Stack
 
Jcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsJcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applications
 
Going FaaSter, Functions as a Service at Netflix
Going FaaSter, Functions as a Service at NetflixGoing FaaSter, Functions as a Service at Netflix
Going FaaSter, Functions as a Service at Netflix
 
Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020
 
Managing the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS LambdaManaging the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS Lambda
 
Guide to Spring Reactive Programming using WebFlux
Guide to Spring Reactive Programming using WebFluxGuide to Spring Reactive Programming using WebFlux
Guide to Spring Reactive Programming using WebFlux
 
Zeebe 0.20.0 Release Webinar - July 22, 2019
Zeebe 0.20.0 Release Webinar - July 22, 2019Zeebe 0.20.0 Release Webinar - July 22, 2019
Zeebe 0.20.0 Release Webinar - July 22, 2019
 
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
 
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar SeriesContinuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

A Tour of Combine