$30 off During Our Annual Pro Sale. View Details »
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
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
250
Kill the mutants, test your tests
joyofcoding
0
95
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
880
The Scientific Programmer - Eric Bouwers
joyofcoding
0
210
Building a web app in an hour - Trisha Gee
joyofcoding
0
270
Other Decks in Technology
See All in Technology
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
9.7k
AI 時代のデータ戦略
na0
5
1k
AI時代のインシデント対応 〜時代を切り抜ける、組織アーキテクチャ〜
jacopen
4
170
一億総業務改善を支える社内AIエージェント基盤の要諦
yukukotani
5
2k
.NET 10のEntity Framework Coreの新機能
htkym
0
140
機械学習を「社会実装」するということ 2025年冬版 / Social Implementation of Machine Learning November 2025 Version
moepy_stats
4
860
命名から始めるSpec Driven
kuruwic
2
650
Flutter Thread Merge - Flutter Tokyo #11
itsmedreamwalker
1
110
変わるもの、変わらないもの :OSSアーキテクチャで実現する持続可能なシステム
gree_tech
PRO
0
1.2k
生成AIシステムとAIエージェントに関する性能や安全性の評価
shibuiwilliam
2
260
不確実性に備える ABEMA の信頼性設計とオブザーバビリティ基盤
nagapad
5
9.2k
ローカルLLM基礎知識 / local LLM basics 2025
kishida
25
11k
Featured
See All Featured
Site-Speed That Sticks
csswizardry
13
970
How GitHub (no longer) Works
holman
316
140k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
A designer walks into a library…
pauljervisheath
210
24k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Thoughts on Productivity
jonyablonski
73
4.9k
The Pragmatic Product Professional
lauravandoore
36
7k
Mobile First: as difficult as doing things right
swwweet
225
10k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
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