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
550
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
340
Chris Granger - PROGRAMMING AS DISTRIBUTED COGNITION: DEFINING A SUPER POWER
joyofcoding
0
240
Cristina Lopes - Exercises in Programming Style
joyofcoding
0
520
Laurent Bossavit - The Joy of Debugging Ourselves
joyofcoding
0
270
Kill the mutants, test your tests
joyofcoding
0
120
Let Me Graph That For You: An Introduction to Neo4j - Ian Robinson
joyofcoding
1
190
Who’s afraid of Object Algebras? - Tijs van der Storm
joyofcoding
0
920
The Scientific Programmer - Eric Bouwers
joyofcoding
0
230
Building a web app in an hour - Trisha Gee
joyofcoding
0
290
Other Decks in Technology
See All in Technology
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
180
AIチャットの改善から見えた、良いAI体験とは / What Constitutes a Good AI Experience: Insights from Improving AI Chat
kubode
0
120
從開發到部署全都交給 AI:實作 AI 驅動的自動化流程
appleboy
0
160
MUSUBI 田中裕一『AIと共に行う「しごとのリデザイン」- スモールバックオフィス編』AI Ops Lab #4
musubi
0
310
クラウドファンディング版StackChan 3体(4体)をインタラクティブな体験型作品にして展示もした話 / スタックチャンお誕生日会2026
you
PRO
0
180
螺旋型キャリアの生存戦略 / kinoko-conf2026
rakus_dev
1
950
FPC(フレキシブル)基板にZephyr実装してみた。
iotengineer22
0
170
元銀行員がAIだけでアプリを量産!「バイブコーディング実演セミナー 」
tatsuya1970
0
110
[AWS Summit Japan 2026]迷っているあなたへ_小さな一歩が、やがて自分を助けてくれる
sh_fk2
2
400
AIはどのように 組織のアジリティを変えるのか?
junki
4
1.3k
5分でわかるDuckDB Quack
chanyou0311
3
250
徹底討論!ECS vs EKS!
daitak
3
1.7k
Featured
See All Featured
Navigating Weather and Climate Data
rabernat
0
230
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
180
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
GitHub's CSS Performance
jonrohan
1033
470k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
66
55k
Visualization
eitanlees
152
17k
Code Reviewing Like a Champion
maltzj
528
40k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Designing for Timeless Needs
cassininazir
1
260
Raft: Consensus for Rubyists
vanstee
141
7.6k
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