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
870
DIY your own Combine framework
Li-Heng Hsu
September 22, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
코틀린으로 멀티플랫폼 만들기
pangmoo
0
120
puregoの活用例
aethiopicuschan
0
220
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
430
ログラスを支える設計標準について / loglass-design-standards
urmot
10
2.1k
Folding Cheat Sheet #1
philipschwarz
PRO
0
210
Code Reviews
bkuhlmann
4
880
デザインシステムで Tailwind CSSとCSS in JSに分散投資をしたら良かった話
fsubal
18
4.8k
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
220
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
340
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
250
From Spring Boot 2 to Spring Boot 3 with Java 21 and Jakarta EE
ivargrimstad
0
1.1k
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
39
18k
Featured
See All Featured
BBQ
matthewcrist
80
8.7k
Designing Experiences People Love
moore
136
23k
Imperfection Machines: The Place of Print at Facebook
scottboms
258
12k
A Tale of Four Properties
chriscoyier
150
22k
What’s in a name? Adding method to the madness
productmarketing
PRO
15
2.6k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
4 Signs Your Business is Dying
shpigford
175
21k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
Gamification - CAS2011
davidbonilla
76
4.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
344
19k
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