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
Contravariance is the Dual of Covariance - Erik...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Joy of Coding
March 07, 2014
Technology
0
540
Contravariance is the Dual of Covariance - Erik Meijer
Joy of Coding
March 07, 2014
Tweet
Share
More Decks by Joy of Coding
See All by Joy of Coding
Cool Code - Kevlin Henney
joyofcoding
0
320
Chris Granger - PROGRAMMING AS DISTRIBUTED COGNITION: DEFINING A SUPER POWER
joyofcoding
0
230
Cristina Lopes - Exercises in Programming Style
joyofcoding
0
500
Laurent Bossavit - The Joy of Debugging Ourselves
joyofcoding
0
260
Kill the mutants, test your tests
joyofcoding
0
100
Let Me Graph That For You: An Introduction to Neo4j - Ian Robinson
joyofcoding
1
170
Who’s afraid of Object Algebras? - Tijs van der Storm
joyofcoding
0
890
The Scientific Programmer - Eric Bouwers
joyofcoding
0
220
Building a web app in an hour - Trisha Gee
joyofcoding
0
280
Other Decks in Technology
See All in Technology
レガシー共有バッチ基盤への挑戦 - SREドリブンなリアーキテクチャリングの取り組み
tatsukoni
0
170
IaaS/SaaS管理における SREの実践 - SRE Kaigi 2026
bbqallstars
4
1.4k
AIとともに歩む情報セキュリティ / Information Security with AI
kanny
4
3.1k
SMTP完全に理解した ✉️
yamatai1212
0
180
開発メンバーが語るFindy Conferenceの裏側とこれから
sontixyou
2
500
データ民主化のための LLM 活用状況と課題紹介(IVRy の場合)
wxyzzz
2
600
MySQLのJSON機能の活用術
ikomachi226
0
130
最速で価値を出すための プロダクトエンジニアのツッコミ術
kaacun
1
520
ゼロから始めたFindy初のモバイルアプリ開発
grandbig
2
640
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
1
390
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
120
What happened to RubyGems and what can we learn?
mikemcquaid
0
200
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
50
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
190
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
110
A Tale of Four Properties
chriscoyier
162
24k
Navigating Team Friction
lara
192
16k
A designer walks into a library…
pauljervisheath
210
24k
Transcript
Rx! from first principles
[email protected]
Getters ()=>A
Covariant A <: B ()=>A <: ()=>B
Functor val map: (A=>B) =>(()=>A)=>()=>B map f a =()=>f(a())
“Monad” val flatMap:(()=>A) =>(A=>(()=>()=>B))=>(()=>B) flatMap a f = ()=>f()(a())()
Side Effects val steveb: ()=>String steveb() // “developer” steveb() //
“blah” steveb() // “Windows 8” steveb() // ☲
Side Effects ()=>Try[A]
Side Effects val sjobs: ()=>String sjobs() // “iPhone” sjobs() //
“iPad” sjobs() // “iCloud” sjobs() // †
Side Effects ()=>Try[Option[A]]
Getter Getter ()=> (()=> Try[Option[A]] )
Interfaces trait Enumerable[+T] { def getEnumerator(): Enumerator[T] } ! trait
Enumerator[+T] { def moveNext(): Boolean def current: T }
Lifting trait Enumerable[+T] { def getEnumerator(): Enumerator[T] ! def lift(f:
Enumerator[T]=>Enumerator[S]): val that = this Enumerable[S] = { new Enumerable[S] { def getEnumerator() = f(that.GetEnumerator()) } } }
Functor val map: (A=>B)=> Enumerable[A]=>Enumerable[B] map f as =
as.lift(_.map)
Monad val flatMap: (A=>Enumerable[B])=> Enumerable[A]=>Enumerable[B] flatmap f as =
as.lift(_.flatmap)
Reverse All Those =>
Setters A=>()
Contravariant A <: B B=>() <: A=>()
coFunctor val map: (A=>B) =>((B=>())=>(A=>())) map f b =
a=>(b(f a))
“Monad” val flatMap:(A=>()) =>(B=>((()=>A)=>())=>(B=>()) flatMap a f = b=>f(b)(a)
Side Effects val emeijer: String=>() emeijer(“Comega”) emeijer(“LINQ”) emeijer(“Rx”) emeijer(☲)
Side Effects Try[A]=>()
Side Effects val kubric: String=>() kubric(“Spartacus”) kubric(“Lolita”) kubric(“Eyes Wide Shut”)
kubric(†)
Side Effects Try[Option[A]]=>()
Setter Setter (Try[Option[A]] => () )=>()
Interfaces trait Observable[+T] { def Subscribe(o: Observer[T]): Unit } !
trait Observer[-T] { def onCompleted(): Unit def onError(error: Throwable): Unit def onNext(value: T): Unit }
Lifting trait Observable[+T] { def subscribe(o: Observer[T]) ! def lift(f:
Observer[S]=>Observer[T]): val that = this Observable[S] = { new Observable[S] { def subscribe(o: Observer[S]) = that.Subscribe(f(o)) } } }
Functor val map: (A=>B)=> Observable[A]=>Observable[B] map f as =
as.lift(_.map)
Monad val flatMap:(A=>Observable[B])=> Observable[A]=>Observable[B] flatmap f as = as.lift(_.flatmap)
Real World
Real World
Real World