Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
DIY your own Combine framework
Search
Li-Heng Hsu
September 22, 2019
Programming
0
1k
DIY your own Combine framework
Li-Heng Hsu
September 22, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
300
AI時代もSEOを頑張っている話
shirahama_x
0
230
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
380
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.1k
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
15
8k
【CA.ai #3】Google ADKを活用したAI Agent開発と運用知見
harappa80
0
260
AIコーディングエージェント(NotebookLM)
kondai24
0
130
AIコーディングエージェント(Manus)
kondai24
0
120
CSC305 Lecture 15
javiergs
PRO
0
250
All(?) About Point Sets
hole
0
260
How Software Deployment tools have changed in the past 20 years
geshan
0
28k
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
10
11k
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
For a Future-Friendly Web
brad_frost
180
10k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
The Cult of Friendly URLs
andyhume
79
6.7k
Visualization
eitanlees
150
16k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Building Adaptive Systems
keathley
44
2.9k
What's in a price? How to price your products and services
michaelherold
246
12k
Transcript
DIY your own Combine framework Basic Functional Reactive Programming concepts
Li-Heng Hsu 許立衡 @ iPlayground 2019
– Apple documentation "The Combine framework provides a declarative Swift
API for processing values over time."
None
Concepts • Builder pattern • map(_:) method
Builder pattern • For constructing instances • Like initializer, factory
method… 1. Create a builder struct 2. Store construction info in it 3. Call its build() method to construct a product
URLComponents URL builder
Combine Subscription builder
Builder pattern Combine Builder Publisher Construction info Operator build() Subscriber
Product Subscription Roles
CombineDIY.swift
map(_:) method • There are different worlds in code •
World of Uncertainty, World of Plurality, World of Erroneous... • Instances in these worlds can't be manipulated normally
Optional World of Uncertainty
World of Uncertainty Cat? (Cat) -> Double (Cat?) -> Double?
map(_:)
None
Imperative Functional Metaphor Unwrap values Stack operations Optional if let
x = x { /* ... */ } x.map { x in /* ... */ } Collection for i in x { /* ... */ } x.forEach { i in /* ... */ } Result if case .success(let x) = result { /* ... */ } result.map { x in /* ... */ }
World of Plurality [Cat] (Cat) -> Double ([Cat]) -> [Double]
map(_:)
World of Temporality Publisher<Cat> (Cat) -> Double (Publisher<Cat>) -> Publisher<Double>
map(_:)
DIY map(_:)
Feedback Come find me! Twitter: @lihenghsu