$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
You Used To Inject Me In Your Constructor
Search
mathonsunday
December 14, 2015
Programming
0
660
You Used To Inject Me In Your Constructor
Presented at Functional Swift Conference 2015.
mathonsunday
December 14, 2015
Tweet
Share
More Decks by mathonsunday
See All by mathonsunday
Pushing SwiftUI To The Limit
mathonsunday
0
20
Prepping For A SwiftUI Future
mathonsunday
0
520
Developing And Testing Complex Permission Flows
mathonsunday
1
210
We Have A Code Of Ethics: Now What?
mathonsunday
0
140
Real World Mocking In Swift
mathonsunday
4
1.7k
Making Swift Even More Functional
mathonsunday
2
400
Making Swift Even More Functional (iOS Dev Camp DC)
mathonsunday
0
110
Friendly Open Source Projects
mathonsunday
0
80
Other Decks in Programming
See All in Programming
全員アーキテクトで挑む、 巨大で高密度なドメインの紐解き方
agatan
8
20k
テストやOSS開発に役立つSetup PHP Action
matsuo_atsushi
0
150
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
380
ゲームの物理 剛体編
fadis
0
320
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
200
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
37
25k
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
190
tparseでgo testの出力を見やすくする
utgwkk
1
180
How Software Deployment tools have changed in the past 20 years
geshan
0
28k
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
260
スタートアップを支える技術戦略と組織づくり
pospome
8
16k
MAP, Jigsaw, Code Golf 振り返り会 by 関東Kaggler会|Jigsaw 15th Solution
hasibirok0
0
230
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
54
7.9k
For a Future-Friendly Web
brad_frost
180
10k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Thoughts on Productivity
jonyablonski
73
5k
Being A Developer After 40
akosma
91
590k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.1k
Site-Speed That Sticks
csswizardry
13
990
YesSQL, Process and Tooling at Scale
rocio
174
15k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
It's Worth the Effort
3n
187
29k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Transcript
You Used To Inject Me In Your Constructor - Functional
Programming In Swift
Hello, I’m Veronica Ray!
–Dependency Injection Demystified “Dependency injection means giving an object its
instance variables. Really. That's it.”
WHY
None
WHY •Clear declaration of dependencies •Composition •Easy customization
WHY •Clear ownership •Testability
FRAMEWORK
None
LAYER OF ABSTRACTION
SUPER LINEAR
SMART FRAMEWORKS
LAZY EVALUATION
–HaskellWiki “…expressions are not evaluated when they are bound to
variables, but their evaluation is deferred until their results are needed by other computations. ”
–HaskellWiki “…Pure computations ..can be performed at any time and
still yield the same result.
–HaskellWiki “This makes it possible to defer the computation of
values until they are needed, that is, to compute them lazily. ”
Lazy evaluation Brought to you by functional programming
MEMOIZATION
–Python 3 Tutorial “ If the same input or a
function call with the same parameters is used, the previously stored results can be used again and unnecessary calculation are avoided.”
SCOPES
TYPHOON
TyphoonScopeSingleton TyphoonScopeLazySingleton
SWINJECT
ObjectScope.Container
None
None
ISSUES
WE NEED A RESOLUTION
DI IN SWIFT •constructor injection •reader monad
DI IN SWIFT •constructor injection •reader monad
BearWithMe Find fiends to hibernate with during the winter
None
None
None
None
–In today’s post-OO world, is dependency injection still relevant? “Currently
we use the same mechanism – parameters – to define the environment (e.g. via constructor parameters), as we use to pass data around functions.”
DI IN SWIFT •constructor injection •reader monad
–Don’t Fear The Reader “…if you break down common dependency
injection libraries they are just different implementations of the Reader Monad pattern.”
None
None
SIMPLE EXAMPLE
DO NOTATION
DESUGARED
SWIFT
BearWithMe Find fiends to hibernate with during the winter
None
None
IS THIS A GOOD IDEA?
USE DEPENDENCY INJECTION
LEARN MORE
•Swiftz •Swift Injection •Nick Santos •objc.io •adit.io
THANK YOU