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
Joy of Coding
March 07, 2014
Technology
540
0
Share
Contravariance is the Dual of Covariance - Erik Meijer
Joy of Coding
March 07, 2014
More Decks by Joy of Coding
See All by Joy of Coding
Cool Code - Kevlin Henney
joyofcoding
0
330
Chris Granger - PROGRAMMING AS DISTRIBUTED COGNITION: DEFINING A SUPER POWER
joyofcoding
0
230
Cristina Lopes - Exercises in Programming Style
joyofcoding
0
510
Laurent Bossavit - The Joy of Debugging Ourselves
joyofcoding
0
260
Kill the mutants, test your tests
joyofcoding
0
110
Let Me Graph That For You: An Introduction to Neo4j - Ian Robinson
joyofcoding
1
180
Who’s afraid of Object Algebras? - Tijs van der Storm
joyofcoding
0
910
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
目的ファーストのハーネス設計 ~ハーネスの変更容易性を高めるための優先順位~
gotalab555
8
2.2k
EarthCopilotに学ぶマルチエージェントオーケストレーション
nakasho
0
300
マルチエージェント × ハーネスエンジニアリング × GitLab Duo Agent Platformで実現する「AIエージェントに仕事をさせる時代へ。」 / 20260421 GitLab Duo Agent Platform
n11sh1
0
160
Master Dataグループ紹介資料
sansan33
PRO
1
4.6k
No Types Needed, Just Callable Method Check
dak2
1
1.3k
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
4
23k
AWS Agent Registry の基礎・概要を理解する/aws-agent-registry-intro
ren8k
3
380
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
74k
Bill One 開発エンジニア 紹介資料
sansan33
PRO
6
18k
小説執筆のハーネスエンジニアリング
yoshitetsu
0
710
Do Vibe Coding ao LLM em Produção para Busca Agêntica - TDC 2026 - Summit IA - São Paulo
jpbonson
3
120
Keeping Ruby Running on Cygwin
fd0
0
160
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
AI: The stuff that nobody shows you
jnunemaker
PRO
6
570
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
The Curious Case for Waylosing
cassininazir
0
300
The Limits of Empathy - UXLibs8
cassininazir
1
300
Un-Boring Meetings
codingconduct
0
270
How to Talk to Developers About Accessibility
jct
2
180
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
810
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
110
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