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
You Used To Inject Me In Your Constructor
Search
mathonsunday
December 14, 2015
Programming
0
590
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
11
Prepping For A SwiftUI Future
mathonsunday
0
400
Developing And Testing Complex Permission Flows
mathonsunday
1
200
We Have A Code Of Ethics: Now What?
mathonsunday
0
97
Real World Mocking In Swift
mathonsunday
4
1.5k
Making Swift Even More Functional
mathonsunday
2
390
Making Swift Even More Functional (iOS Dev Camp DC)
mathonsunday
0
110
Friendly Open Source Projects
mathonsunday
0
71
Other Decks in Programming
See All in Programming
Understanding Ast By Looking
inouehi
0
120
コミュニティに参加したことで起きた変化
ohmori_yusuke
3
130
incrementalモデルの理解を深める
ikkimiyazaki
2
630
20240301_cocone_EMゆるミートアップvol6_LT資料
cocone
0
310
Building a Smaller App Binary
kateinoigakukun
2
190
イベントストーミングによるオブジェクトモデリング・オブジェクト指向プログラミングの適用・開発プロセスの変遷・アーキテクチャの変革 / Object modeling with Event Storming.
nrslib
12
2.3k
WinUI 3デモ - "CommunityToolkit.Mvvm"NuGetパッケージ編
andrewkeepcoding
0
130
CSRF対策のやり方、そろそろアップデートしませんか / Update your knowledge of CSRF protection
hiro_y
25
13k
Docker ハンズオン / docker-hands-on
suzukihoge
51
16k
Parallel Socket Communication in Swift
s_shimotori
0
210
【KMC春合宿2024】実装視点で見るNeural Radiance Fields
runningoutrate
0
150
もうすぐ新年度、Babylon.jsがお勧めな3個の理由
hideg
0
160
Featured
See All Featured
Embracing the Ebb and Flow
colly
78
4.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
355
22k
What's in a price? How to price your products and services
michaelherold
236
11k
For a Future-Friendly Web
brad_frost
170
8.9k
A Philosophy of Restraint
colly
195
15k
What’s in a name? Adding method to the madness
productmarketing
PRO
14
2.6k
Become a Pro
speakerdeck
PRO
8
4.4k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
Music & Morning Musume
bryan
39
5.5k
A designer walks into a library…
pauljervisheath
199
23k
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
Robots, Beer and Maslow
schacon
PRO
154
7.9k
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