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
Joy of Coding
March 07, 2014
Technology
0
520
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
290
Chris Granger - PROGRAMMING AS DISTRIBUTED COGNITION: DEFINING A SUPER POWER
joyofcoding
0
210
Cristina Lopes - Exercises in Programming Style
joyofcoding
0
470
Laurent Bossavit - The Joy of Debugging Ourselves
joyofcoding
0
200
Kill the mutants, test your tests
joyofcoding
0
72
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
800
The Scientific Programmer - Eric Bouwers
joyofcoding
0
190
Building a web app in an hour - Trisha Gee
joyofcoding
0
240
Other Decks in Technology
See All in Technology
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Terraform Stacks入門 #HashiTalks
msato
0
350
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
750
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
370
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Application Development WG Intro at AppDeveloperCon
salaboy
0
180
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
5
610
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Done Done
chrislema
181
16k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
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