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 Meijer
Search
Joy of Coding
March 07, 2014
Technology
0
490
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
280
Chris Granger - PROGRAMMING AS DISTRIBUTED COGNITION: DEFINING A SUPER POWER
joyofcoding
0
180
Cristina Lopes - Exercises in Programming Style
joyofcoding
0
450
Laurent Bossavit - The Joy of Debugging Ourselves
joyofcoding
0
170
Kill the mutants, test your tests
joyofcoding
0
66
Let Me Graph That For You: An Introduction to Neo4j - Ian Robinson
joyofcoding
1
140
Who’s afraid of Object Algebras? - Tijs van der Storm
joyofcoding
0
730
The Scientific Programmer - Eric Bouwers
joyofcoding
0
170
Building a web app in an hour - Trisha Gee
joyofcoding
0
230
Other Decks in Technology
See All in Technology
20240418_Google ColabにLLMが搭載されたようなのでPython x データ分析の勉強方法を考えてみる
doradora09
0
120
日本におけるデータエンジニアリングのこれまでとこれから
foursue
16
4.2k
web-application-security
matsuihidetoshi
0
140
VS CodeでAWSを操作しよう
smt7174
7
1.6k
元インフラエンジニアに成る / Human Resources to Human Relations
bobtani
4
900
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
1
190
Azure Container Apps + Bicep 〜 こんな感じで運用しています
kaz29
2
440
AOAI をきっかけに 社内の Azure 管理を見直した話
recruitengineers
PRO
1
260
ゼロから始めるVue.jsコミュニティ貢献 / first-vuejs-community-contribution-link-and-motivation
lmi
1
110
エンジニア候補者向け資料2024.04.24.pdf
macloud
0
3.3k
データベース02: データベースの概念
trycycle
0
150
開発生産性大幅アップ!Postman VS Code拡張機能
nagix
2
360
Featured
See All Featured
What's new in Ruby 2.0
geeforr
337
31k
Build The Right Thing And Hit Your Dates
maggiecrowley
24
2k
A Modern Web Designer's Workflow
chriscoyier
689
190k
Infographics Made Easy
chrislema
238
18k
Product Roadmaps are Hard
iamctodd
44
9.7k
The Cost Of JavaScript in 2023
addyosmani
16
3.8k
Docker and Python
trallard
34
2.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
104
6.6k
[RailsConf 2023] Rails as a piece of cake
palkan
23
3.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