Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
爆速スッキリ! Rspack 移行の成果と道のり - Muddy Web #11
dora1998
0
130
OUPC2024 Day 1 解説
kowerkoint
0
390
Go1.24で testing.B.Loopが爆誕
kuro_kurorrr
0
140
Gunma.web #55
tinykitten
0
130
Going Structural with Named Tuples
bishabosha
0
140
RCPと宣言型ポリシーについてのお話し
kokitamura
2
130
Fluent UI Blazor 5 (alpha)の紹介
tomokusaba
0
110
SLI/SLOの設定を進めるその前に アラート品質の改善に取り組んだ話
tanden
2
630
Develop Faster With FrankenPHP
dunglas
1
1.4k
JavaOne 2025: Advancing Java Profiling
jbachorik
1
300
Kubernetesで実現できるPlatform Engineering の現在地
nwiizo
2
1.6k
アーキテクトと美学 / Architecture and Aesthetics
nrslib
11
2.9k
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
41
2.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
134
33k
Mobile First: as difficult as doing things right
swwweet
223
9.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
It's Worth the Effort
3n
184
28k
Optimizing for Happiness
mojombo
377
70k
GraphQLとの向き合い方2022年版
quramy
45
14k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
12
1.4k
Testing 201, or: Great Expectations
jmmastey
42
7.3k
KATA
mclloyd
29
14k
Thoughts on Productivity
jonyablonski
69
4.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
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