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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
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
100
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
900
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
Postman v12 で変わる API開発ワークフロー (Postman v12 アップデート) / New API development workflow with Postman v12
yokawasa
0
130
Claude Code Skills 勉強会 (DevelersIO向けに調整済み) / claude code skills for devio
masahirokawahara
1
21k
AWSの資格って役に立つの?
tk3fftk
2
340
社内レビューは機能しているのか
matsuba
0
130
Go標準パッケージのI/O処理をながめる
matumoto
0
210
わたしがセキュアにAWSを使えるわけないじゃん、ムリムリ!(※ムリじゃなかった!?)
cmusudakeisuke
1
750
身体を持ったパーソナルAIエージェントの 可能性を探る開発
yokomachi
1
120
AI駆動AI普及活動 ~ 社内AI活用の「何から始めれば?」をAIで突破する
oracle4engineer
PRO
1
100
Kubernetesにおける推論基盤
ry
1
390
It’s “Time” to use Temporal
sajikix
1
160
Zeal of the Convert: Taming Shai-Hulud with AI
ramimac
0
110
決済サービスを支えるElastic Cloud - Elastic Cloudの導入と推進、決済サービスのObservability
suzukij
2
640
Featured
See All Featured
Statistics for Hackers
jakevdp
799
230k
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.4k
Amusing Abliteration
ianozsvald
0
130
Mobile First: as difficult as doing things right
swwweet
225
10k
Marketing to machines
jonoalderson
1
5k
Darren the Foodie - Storyboard
khoart
PRO
3
2.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
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