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
410
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
210
Other Decks in Programming
See All in Programming
GraphQL×Railsアプリのデータベース負荷分散 - 月間3,000万人利用サービスを無停止で
koxya
1
1.3k
バッチ処理を「状態の記録」から「事実の記録」へ
panda728
PRO
0
150
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
300
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
止められない医療アプリ、そっと Swift 6 へ
medley
1
160
Railsだからできる 例外業務に禍根を残さない 設定設計パターン
ei_ei_eiichi
0
460
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
250
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
dynamic!
moro
10
7.3k
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
360
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
220
Web Components で実現する Hotwire とフロントエンドフレームワークの橋渡し / Bridging with Web Components
da1chi
3
2.1k
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Agile that works and the tools we love
rasmusluckow
331
21k
Embracing the Ebb and Flow
colly
88
4.8k
Mobile First: as difficult as doing things right
swwweet
224
10k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
590
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
900
It's Worth the Effort
3n
187
28k
Balancing Empowerment & Direction
lara
4
680
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
45
2.5k
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!