Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Contravariance is the Dual of Covariance - Erik...
Search
Joy of Coding
March 07, 2014
Technology
560
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
Transcript
31 slides
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
More Decks by Joy of Coding
See All by Joy of Coding
Cool Code - Kevlin Henney
joyofcoding
0
360
Chris Granger - PROGRAMMING AS DISTRIBUTED COGNITION: DEFINING A SUPER POWER
joyofcoding
0
260
Cristina Lopes - Exercises in Programming Style
joyofcoding
0
530
Laurent Bossavit - The Joy of Debugging Ourselves
joyofcoding
0
290
Kill the mutants, test your tests
joyofcoding
0
130
Let Me Graph That For You: An Introduction to Neo4j - Ian Robinson
joyofcoding
1
210
Who’s afraid of Object Algebras? - Tijs van der Storm
joyofcoding
0
950
The Scientific Programmer - Eric Bouwers
joyofcoding
0
240
Building a web app in an hour - Trisha Gee
joyofcoding
0
300
Other Decks in Technology
See All in Technology
[関西Kaggler会 20261113] 続・コミュニティコンペのススメ
nejumi
0
140
【Oracle AI SPOTLIGHT ウェビナー】【特別開催:日本語で解説!】Oracle AI World 2026 最新情報フィードバック
oracle4engineer
PRO
1
270
BALLAS Technology Deck
ballas_inc
0
840
Re:ゼロから始めるシェアハウスのペットな鯖
silmin_
0
240
異夢同船〜異なる夢でも同じ船でなんとかする〜
fortegp05
1
500
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
17
120k
農家は秘伝のタレを知らない - NOBODY KNOWS THE HIDDEN SOURCE - Kaggriculture 3rd Place Solution
masspeaks
2
510
cdkdがどんだけ早いか、実際に動かして見てみよう
smt7174
1
130
目を覚ませ!僕らの認証情報が何者かに侵略されてるぞ
tkito
2
450
Claude Securityを使ってみた / claude-security-claude-code-meetup-nagoya
tnir
0
140
Shared Signals Framework 仕様解説
oidfj
0
480
Sonnetだけで業務はまわる?
kintotechdev
1
140
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
750
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
400
Bash Introduction
62gerente
615
220k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1.1k
The Limits of Empathy - UXLibs8
cassininazir
2
790
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
610
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
640