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
Parallel Universes - Reader and Coreader for Sw...
Search
Elmar Kretzer
September 30, 2017
Programming
1
210
Parallel Universes - Reader and Coreader for Swift DI
Slides are from my talk at Functional Swift Conference 2017 in Berlin.
http://www.funswiftconf.com
Elmar Kretzer
September 30, 2017
Tweet
Share
More Decks by Elmar Kretzer
See All by Elmar Kretzer
Reusable Animations in Swift
elmkretzer
2
400
A swift 4 KeyPath journey
elmkretzer
2
990
Palau - NSUserDefaults with Wings!
elmkretzer
1
170
Swift Generics
elmkretzer
4
420
Migrating Objective-C to Swift
elmkretzer
0
200
Other Decks in Programming
See All in Programming
新メンバーも今日から大活躍!SREが支えるスケールし続ける組織のオンボーディング
honmarkhunt
5
7.3k
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
390
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
450
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
190
AIともっと楽するE2Eテスト
myohei
6
2.6k
Team operations that are not burdened by SRE
kazatohiei
1
310
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
590
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
290
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
170
AI時代の『改訂新版 良いコード/悪いコードで学ぶ設計入門』 / ai-good-code-bad-code
minodriven
14
4.6k
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
820
Featured
See All Featured
Practical Orchestrator
shlominoach
189
11k
Faster Mobile Websites
deanohume
307
31k
Code Review Best Practice
trishagee
69
18k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
KATA
mclloyd
30
14k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Six Lessons from altMBA
skipperchong
28
3.9k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Transcript
Parallel Universes Reader & Coreader for Dependency Injection Ì INCL.
COMONADS, MONADS & THE DISTANT PAST Elmar Kretzer @elmkretzer
- talk to network - use Date() - persist data
Does your app even: - you name it Why care?
HOW TO? ... wire it together? ... test it peacefully?
... set it up?
highly flexible duplication of code mental overhead error prone Keep
It Pass On 1 2
3 OPTIONS: „DO IT MANUALLY“ „USE A FRAMEWORK“ „DO SOMETHING
ELSE“
Let’s talk about „something else“ Functional Programming Weirder names for
weird concepts. Some/None/Few/All people like it.
But Swift does use/allow/force functional patterns. Sometimes you don’t even
notice. Swift Guess who’s not a Functional PL:
empowered by fp
FP & DI – Cool & How?
http://hackage.haskell.org/package/mtl-1.1.0.2/docs/Control-Monad-Reader.html „Represents a computation, which can read values from a
shared environment, pass values from function to function, and execute sub-computations in a modified environment.“ 1/2 READER MONAD
very abstract return sth. based on sth. else afterwards pass
it on to get sth. that itself returns sth. based on sth. else
Describe dependent operations. Provide How at the end. 100 +
10 + 5 + 2 100 * 10 * 5 * 2 100 - 10 - 5 - 2 100 / 10 / 5 / 2
„In more technical language the Reader comonad is left adjoint
to the Reader monad.“ 2/2 READER COMONAD https://hackage.haskell.org/package/category-extras-0.53.0/docs/Control-Comonad-Reader.html
very co-abstract hold sth. and sth. else afterwards get sth.
new from sth. and sth. else and return the new with sth. else
Describe dependent access. Provide from WHAT at the end. RealWorld
-> Api -> Server -> Time MockWorld - > Api -> Server -> Time
Reader vs Coreader Comonad extend M a -> M a
-> b -> M b Produce -> Consume Cokleisli Monad flatMap M a -> a -> M b -> M b Consume -> Produce Kleisli
Coreader No. B/C Controller, Storyboards and so forth. Reader Yes.
No one is holding you back. Worth it & simple to use in iOS?
What do you do? Corridor µFramework for a Coreader-like
access to dependencies. Combined with Reader: full-fledged control. github.com/symentis/Corridor
Pro? Unified Handling of DI. No business code for passing
on Dependencies. Dependencies are transparent. Testing simply takes different Environments. Less code. More safety.
Follow-Up article including gists on: http://elm4ward.github.io/ Corridor on GitHub: https://github.com/symentis/Corridor
Me on Twitter: @elmkretzer thanks for your time!