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
990
DIY your own Combine framework
Li-Heng Hsu
September 22, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
color-scheme: light dark; を完全に理解する
uhyo
3
280
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
900
CNCF Project の作者が考えている OSS の運営
utam0k
6
710
2024年のWebフロントエンドのふりかえりと2025年
sakito
2
240
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
140
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
550
How mixi2 Uses TiDB for SNS Scalability and Performance
kanmo
36
14k
WebDriver BiDiとは何なのか
yotahada3
1
140
SpringBoot3.4の構造化ログ #kanjava
irof
2
990
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
120
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
0
190
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
1k
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Being A Developer After 40
akosma
89
590k
Into the Great Unknown - MozCon
thekraken
35
1.6k
We Have a Design System, Now What?
morganepeng
51
7.4k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Code Reviewing Like a Champion
maltzj
521
39k
Statistics for Hackers
jakevdp
797
220k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
The Pragmatic Product Professional
lauravandoore
32
6.4k
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