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
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
350
Chris Granger - PROGRAMMING AS DISTRIBUTED COGNITION: DEFINING A SUPER POWER
joyofcoding
0
250
Cristina Lopes - Exercises in Programming Style
joyofcoding
0
530
Laurent Bossavit - The Joy of Debugging Ourselves
joyofcoding
0
280
Kill the mutants, test your tests
joyofcoding
0
120
Let Me Graph That For You: An Introduction to Neo4j - Ian Robinson
joyofcoding
1
200
Who’s afraid of Object Algebras? - Tijs van der Storm
joyofcoding
0
930
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
指示待ちから変化に応じるClaude Codeへ!~環境からAgentへの帰り道を作る~
gotalab555
9
1.7k
AI駆動開発をチームに根付かせる - 「1行も書かない」チームがHarnessを育てた1年 -
kenichirokimura
6
3.5k
AIレビュー時代に必要なのは、SLOで引く撤退ライン
nobuoooo
0
160
Point Cloud as a Foreign Language for Multi-modal Large Language Model
takmin
0
340
Cloudflare製品を活用した AIガバナンス実践入門 / AI governance with Cloudflare Service
delta_tech
1
160
AI駆動開発を組織で促すために
lycorptech_jp
PRO
7
9k
ブラウザで変わるID連携(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
430
サーバー常駐型の 簡易障害調査AI エージェントを作ってみた話
masayoshi
1
500
AI時代のデータ基盤を考える問い
pacocat
0
790
AIエージェントを雇う前に決める5つのこと
knishioka
1
110
[ホンマでっか SRE] あなたはなぜ SRE に?
_awache
0
550
APIセキュリティを組織で実現するには~注力する点と設計・実装に入れたい対策~
riiimparm
2
830
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
450
A designer walks into a library…
pauljervisheath
211
24k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Navigating Weather and Climate Data
rabernat
0
500
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Skip the Path - Find Your Career Trail
mkilby
1
210
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
310
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
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