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
210
Other Decks in Programming
See All in Programming
DataformでPythonする / dataform-de-python
snhryt
0
160
中級グラフィックス入門~効率的なメッシュレット描画~
projectasura
4
2.6k
Amazon Q CLI開発で学んだAIコーディングツールの使い方
licux
3
180
コーディングは技術者(エンジニア)の嗜みでして / Learning the System Development Mindset from Rock Lady
mackey0225
2
440
Vibe coding コードレビュー
kinopeee
0
430
LLMは麻雀を知らなすぎるから俺が教育してやる
po3rin
3
2.1k
Comparing decimals in Swift Testing
417_72ki
0
170
AIコーディングエージェント全社導入とセキュリティ対策
hikaruegashira
16
9.8k
Understanding Ruby Grammar Through Conflicts
yui_knk
1
100
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
620
Nuances on Kubernetes - RubyConf Taiwan 2025
envek
0
150
202507_ADKで始めるエージェント開発の基本 〜デモを通じて紹介〜(奥田りさ)The Basics of Agent Development with ADK — A Demo-Focused Introduction
risatube
PRO
6
1.4k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
Visualization
eitanlees
146
16k
How STYLIGHT went responsive
nonsquared
100
5.7k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.6k
Optimizing for Happiness
mojombo
379
70k
Statistics for Hackers
jakevdp
799
220k
The Invisible Side of Design
smashingmag
301
51k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
GraphQLとの向き合い方2022年版
quramy
49
14k
Making Projects Easy
brettharned
117
6.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
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!