SlideShare une entreprise Scribd logo
1  sur  75
Télécharger pour lire hors ligne
1 
Containers and Aggregates, 
Mutators and Isolates 
for Reactive Programming 
Aleksandar Prokopec, Philipp Haller, Martin Odersky
Reactive Collections 
http://reactive-collections.com 
2
Reactive 
3
4
5 
Observables (event streams)
6 
Observables (event streams) 
• declarative 
val log = messages .filter(_.length < 100) .scan(_ + “n” + _)
7 
Observables (event streams) 
• declarative 
val log = messages .filter(_.length < 100) .scan(_ + “n” + _) 
var log = “” def receive = { case s: String => if (s.length < 100) log = log + “n” + s }
8 
Actors 
• encapsulate mutable state
9 
Actors 
• encapsulate mutable state 
var log = “” def receive = { case s: String => if (s.length < 100) log = log + “n” + s }
10 
Reactive collections 
Isolate Reactive Channel 
Actor ? ActorRef 
? 
Observable 
Observable
11 
Reactive values
Reactive[T] 
12
val ticks: Reactive[Long] 
13 
ticks 
1 
1 
2 
2 
3 
3 
4 
4 
60 
60 
61 
61
ticks onEvent { x => log.debug(s”tick no.$x”) } 
14 
1 
2 
3 
4 
60 
61 
tick no.1 
tick no.2 
tick no.3 
tick no.4 
tick no.60 
tick no.61 
...
ticks foreach { x => log.debug(s”tick no.$x”) } 
15 
1 
2 
3 
4 
60 
61
16 
for (x <- ticks) { log.debug(s”tick no.$x”) } 
Single-threaded!
17 
Reactive combinators
for (x <- ticks) yield { 
x / 60 
} 
18
val seconds: Reactive[Long] = for (x <- ticks) yield { x / 60 } 
19
60 
61 
val seconds: Reactive[Long] = for (x <- ticks) yield { x / 60 } 
20 
ticks 
1 
1 
2 
2 
3 
3 
60 
61 
seconds 
0 
0 
0 
1 
1 
ticks 
seconds 
0 
1
val days: Reactive[Long] = seconds.map(_ / 86400) 
21
val days: Reactive[Long] = 
seconds.map(_ / 86400) 
val secondsToday = 
22
val days: Reactive[Long] = seconds.map(_ / 86400) val secondsToday = (seconds zip days) { (s, d) => s – d * 86400 } 
23
val angle = 
secondsInDay.map(angleFunc) 
24
val angle = secondsInDay.map(angleFunc) val light = secondsInDay.map(lightFunc) 
25
26
27 
val rotate = keys 
a ↓ 
shift ↓ 
a ↑ 
shift ↑ 
pgup ↓ 
pgup ↑ 
keys
28 
val rotate = keys.filter(_ == PAGEUP) 
a ↓ 
shift ↓ 
a ↑ 
shift ↑ 
pgup ↓ 
pgup ↑ 
keys 
pgup ↓ 
pgup ↑ 
filter
29 
val rotate = 
keys.filter(_ == PAGEUP) 
.map(_.down) 
a ↓ 
shift ↓ 
a ↑ 
shift ↑ 
pgup ↓ 
pgup ↑ 
keys 
pgup ↓ 
pgup ↑ 
filter 
true 
false 
map
30 
if (rotate()) viewAngle += 1 
true 
false 
map
31 
Signals
32 
trait Signal[T] extends Reactive[T] { def apply(): T }
33 
val rotate = 
keys.filter(_ == PAGEUP) 
.map(_.down) 
.signal(false) 
true 
false 
map 
signal
34 
val rotate: Signal[Boolean] = keys.filter(_ == PAGEUP) .map(_.down) .signal(false) 
true 
false 
map 
signal
35 
val rotate: Signal[Boolean] val ticks: Reactive[Long] 
ticks
36 
val rotate: Signal[Boolean] 
val ticks: Reactive[Long] 
ticks 
rotate
37 
val rotate: Signal[Boolean] 
val ticks: Reactive[Long] 
val viewAngle: Signal[Double] = 
ticks 
rotate 
viewAngle
38 
val rotate: Signal[Boolean] val ticks: Reactive[Long] val viewAngle: Signal[Double] = ticks.scanPast(0.0) 
ticks 
rotate 
viewAngle
39 
val rotate: Signal[Boolean] val ticks: Reactive[Long] val viewAngle: Signal[Double] = ticks.scanPast(0.0) { (a, _) => if (rotate()) a + 1 else a } 
ticks 
rotate 
viewAngle
40
41 
val velocity = 
ticks.scanPast(0.0) { 
(v, _) => 
} 
val viewAngle =
42 
val velocity = ticks.scanPast(0.0) { (v, _) => if (rotate()) v + 1 } val viewAngle =
43 
val velocity = 
ticks.scanPast(0.0) { 
(v, _) => 
if (rotate()) v + 1 
else v – 0.5 } 
val viewAngle =
44 
val velocity = ticks.scanPast(0.0) { (v, _) => if (rotate()) v + 1 else v – 0.5 } val viewAngle = velocity.scanPast(0.0)(_ + _)
45
46 
Reactive mutators
47 
class Matrix { 
def apply(x: Int, y: Int): Double 
def update(x: Int, y: Int, v: Double) 
}
48 
val screenMat: Signal[Matrix] = (projMat zip viewMat)(_ * _) val invScreenMat = screenMat.map(_.inverse)
49 
Reactive[immutable.Matrix[T]]
50 
val screenMat: Signal[Matrix] = (projMat zip viewMat)(_ * _) val invScreenMat = screenMat.map(_.inverse) 
(4*4*8 + 16 + 16)*4*100 = 64 kb/s
51 
val screenMat = Mutable(new Matrix) (projMat, viewMat).mutate(screenMat) { (p, v) => screenMat().assignMul(p, v) } val invScreenMat = Mutable(new Matrix) screenMat.mutate(invScreenMat) { m => invScreenMat().assignInv(m) }
52 
Reactive collections
53
54 
val selected: Reactive[Set[Character]]
55 
val selected: ReactSet[Character]
56 
trait ReactSet[T] extends ReactContainer[T] { def apply(x: T): Boolean }
57 
trait ReactContainer[T] { 
def inserts: Reactive[T] 
def removes: Reactive[T] 
}
58 
A reactive collection is a pair of reactive values
59 
val selected = 
new ReactHashSet[Character]
60
61 
val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c)))
62 
class ReactContainer[T] { self => def inserts: Reactive[T] def removes: Reactive[T] def map[S](f: T => S) = new ReactContainer[S] { def inserts: Reactive[T] = self.inserts.map(f) def removes: Reactive[T] = self.removes.map(f) } }
63 
val selected = 
new ReactHashSet[Character] 
val decorations = selected 
.map(c => (c, decoFor(c))) 
.to[ReactHashMap]
64 
val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .to[ReactHashMap]
65 
val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .to[ReactHashMap]
66 
val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .to[ReactHashMap]
67 
val selected = 
new ReactHashSet[Character] 
val decorations = selected 
.map(c => (c, decoFor(c))) 
.react.to[ReactHashMap]
68 
val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .react.to[ReactHashMap]
69 
val selected = 
new ReactHashSet[Character] 
val decorations = selected 
.map(c => (c, decoFor(c))) 
.react.to[ReactHashMap]
70 
val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .react.to[ReactHashMap]
71 
Isolates
72 
UI isolate 
class UI extends Isolate[UI.Message] { val frames = source.filter(_ == UI.Frame) val exit = source onCase { case UI.Exit => exit() } } 
Source
73 
UI Isolate 
Source 
AI Isolate 
Source 
Channel[AI.Message]  
 Channel[UI.Message]
74 
Reactive collections 
Isolate Reactive Channel 
Actor ? ActorRef 
? Observable Observable
75 
Thank you!

Contenu connexe

Tendances

The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196Mahmoud Samir Fayed
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceAlexey Raga
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4Kunihiko Saito
 
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196Mahmoud Samir Fayed
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Leonardo Borges
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84Mahmoud Samir Fayed
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idrisConor Farrell
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!mickey24
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
SOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean ArchitectureSOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean ArchitectureFabio Collini
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingSergey Shishkin
 
Effector: we need to go deeper
Effector: we need to go deeperEffector: we need to go deeper
Effector: we need to go deeperVictor Didenko
 

Tendances (20)

The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196The Ring programming language version 1.7 book - Part 40 of 196
The Ring programming language version 1.7 book - Part 40 of 196
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritance
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4
 
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196
 
Error Handling in Scala
Error Handling in ScalaError Handling in Scala
Error Handling in Scala
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84
 
Test (S) on R
Test (S) on RTest (S) on R
Test (S) on R
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
Ray Tracing with ZIO
Ray Tracing with ZIORay Tracing with ZIO
Ray Tracing with ZIO
 
Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idris
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
SOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean ArchitectureSOLID principles in practice: the Clean Architecture
SOLID principles in practice: the Clean Architecture
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional Programming
 
Effector: we need to go deeper
Effector: we need to go deeperEffector: we need to go deeper
Effector: we need to go deeper
 
ScalaMeter 2012
ScalaMeter 2012ScalaMeter 2012
ScalaMeter 2012
 
C programs
C programsC programs
C programs
 
PROGRAM pod
PROGRAM podPROGRAM pod
PROGRAM pod
 

Similaire à Reactive Collections

ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine Aleksandar Prokopec
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88Mahmoud Samir Fayed
 
Crushing the Head of the Snake by Robert Brewer PyData SV 2014
Crushing the Head of the Snake by Robert Brewer PyData SV 2014Crushing the Head of the Snake by Robert Brewer PyData SV 2014
Crushing the Head of the Snake by Robert Brewer PyData SV 2014PyData
 
Funtional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWTFuntional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWTVasil Remeniuk
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
Constraint Programming in Haskell
Constraint Programming in HaskellConstraint Programming in Haskell
Constraint Programming in HaskellDavid Overton
 
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84Mahmoud Samir Fayed
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik ErlandsonDatabricks
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bPhilip Schwarz
 
Matematika Dasar (exponen,dan banyak lagi)
Matematika Dasar (exponen,dan banyak lagi)Matematika Dasar (exponen,dan banyak lagi)
Matematika Dasar (exponen,dan banyak lagi)Lufikome
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchAhmed BESBES
 
Sistemas de control para ingenieria 3ra edicion norman s. nise sol
Sistemas de control para ingenieria  3ra edicion  norman s. nise solSistemas de control para ingenieria  3ra edicion  norman s. nise sol
Sistemas de control para ingenieria 3ra edicion norman s. nise solNielsy Quiroga
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with RYanchang Zhao
 

Similaire à Reactive Collections (20)

ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
 
ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
 
2.3 implicits
2.3 implicits2.3 implicits
2.3 implicits
 
Crushing the Head of the Snake by Robert Brewer PyData SV 2014
Crushing the Head of the Snake by Robert Brewer PyData SV 2014Crushing the Head of the Snake by Robert Brewer PyData SV 2014
Crushing the Head of the Snake by Robert Brewer PyData SV 2014
 
Funtional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWTFuntional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWT
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
Taller 2. 4264. (2)
Taller 2. 4264. (2)Taller 2. 4264. (2)
Taller 2. 4264. (2)
 
Constraint Programming in Haskell
Constraint Programming in HaskellConstraint Programming in Haskell
Constraint Programming in Haskell
 
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84
 
Reactive x
Reactive xReactive x
Reactive x
 
Ch4
Ch4Ch4
Ch4
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
 
Scala intro workshop
Scala intro workshopScala intro workshop
Scala intro workshop
 
Matematika Dasar (exponen,dan banyak lagi)
Matematika Dasar (exponen,dan banyak lagi)Matematika Dasar (exponen,dan banyak lagi)
Matematika Dasar (exponen,dan banyak lagi)
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from Scratch
 
Sistemas de control para ingenieria 3ra edicion norman s. nise sol
Sistemas de control para ingenieria  3ra edicion  norman s. nise solSistemas de control para ingenieria  3ra edicion  norman s. nise sol
Sistemas de control para ingenieria 3ra edicion norman s. nise sol
 
Servo systems
Servo systemsServo systems
Servo systems
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with R
 

Dernier

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 

Dernier (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 

Reactive Collections

  • 1. 1 Containers and Aggregates, Mutators and Isolates for Reactive Programming Aleksandar Prokopec, Philipp Haller, Martin Odersky
  • 4. 4
  • 6. 6 Observables (event streams) • declarative val log = messages .filter(_.length < 100) .scan(_ + “n” + _)
  • 7. 7 Observables (event streams) • declarative val log = messages .filter(_.length < 100) .scan(_ + “n” + _) var log = “” def receive = { case s: String => if (s.length < 100) log = log + “n” + s }
  • 8. 8 Actors • encapsulate mutable state
  • 9. 9 Actors • encapsulate mutable state var log = “” def receive = { case s: String => if (s.length < 100) log = log + “n” + s }
  • 10. 10 Reactive collections Isolate Reactive Channel Actor ? ActorRef ? Observable Observable
  • 13. val ticks: Reactive[Long] 13 ticks 1 1 2 2 3 3 4 4 60 60 61 61
  • 14. ticks onEvent { x => log.debug(s”tick no.$x”) } 14 1 2 3 4 60 61 tick no.1 tick no.2 tick no.3 tick no.4 tick no.60 tick no.61 ...
  • 15. ticks foreach { x => log.debug(s”tick no.$x”) } 15 1 2 3 4 60 61
  • 16. 16 for (x <- ticks) { log.debug(s”tick no.$x”) } Single-threaded!
  • 18. for (x <- ticks) yield { x / 60 } 18
  • 19. val seconds: Reactive[Long] = for (x <- ticks) yield { x / 60 } 19
  • 20. 60 61 val seconds: Reactive[Long] = for (x <- ticks) yield { x / 60 } 20 ticks 1 1 2 2 3 3 60 61 seconds 0 0 0 1 1 ticks seconds 0 1
  • 21. val days: Reactive[Long] = seconds.map(_ / 86400) 21
  • 22. val days: Reactive[Long] = seconds.map(_ / 86400) val secondsToday = 22
  • 23. val days: Reactive[Long] = seconds.map(_ / 86400) val secondsToday = (seconds zip days) { (s, d) => s – d * 86400 } 23
  • 24. val angle = secondsInDay.map(angleFunc) 24
  • 25. val angle = secondsInDay.map(angleFunc) val light = secondsInDay.map(lightFunc) 25
  • 26. 26
  • 27. 27 val rotate = keys a ↓ shift ↓ a ↑ shift ↑ pgup ↓ pgup ↑ keys
  • 28. 28 val rotate = keys.filter(_ == PAGEUP) a ↓ shift ↓ a ↑ shift ↑ pgup ↓ pgup ↑ keys pgup ↓ pgup ↑ filter
  • 29. 29 val rotate = keys.filter(_ == PAGEUP) .map(_.down) a ↓ shift ↓ a ↑ shift ↑ pgup ↓ pgup ↑ keys pgup ↓ pgup ↑ filter true false map
  • 30. 30 if (rotate()) viewAngle += 1 true false map
  • 32. 32 trait Signal[T] extends Reactive[T] { def apply(): T }
  • 33. 33 val rotate = keys.filter(_ == PAGEUP) .map(_.down) .signal(false) true false map signal
  • 34. 34 val rotate: Signal[Boolean] = keys.filter(_ == PAGEUP) .map(_.down) .signal(false) true false map signal
  • 35. 35 val rotate: Signal[Boolean] val ticks: Reactive[Long] ticks
  • 36. 36 val rotate: Signal[Boolean] val ticks: Reactive[Long] ticks rotate
  • 37. 37 val rotate: Signal[Boolean] val ticks: Reactive[Long] val viewAngle: Signal[Double] = ticks rotate viewAngle
  • 38. 38 val rotate: Signal[Boolean] val ticks: Reactive[Long] val viewAngle: Signal[Double] = ticks.scanPast(0.0) ticks rotate viewAngle
  • 39. 39 val rotate: Signal[Boolean] val ticks: Reactive[Long] val viewAngle: Signal[Double] = ticks.scanPast(0.0) { (a, _) => if (rotate()) a + 1 else a } ticks rotate viewAngle
  • 40. 40
  • 41. 41 val velocity = ticks.scanPast(0.0) { (v, _) => } val viewAngle =
  • 42. 42 val velocity = ticks.scanPast(0.0) { (v, _) => if (rotate()) v + 1 } val viewAngle =
  • 43. 43 val velocity = ticks.scanPast(0.0) { (v, _) => if (rotate()) v + 1 else v – 0.5 } val viewAngle =
  • 44. 44 val velocity = ticks.scanPast(0.0) { (v, _) => if (rotate()) v + 1 else v – 0.5 } val viewAngle = velocity.scanPast(0.0)(_ + _)
  • 45. 45
  • 47. 47 class Matrix { def apply(x: Int, y: Int): Double def update(x: Int, y: Int, v: Double) }
  • 48. 48 val screenMat: Signal[Matrix] = (projMat zip viewMat)(_ * _) val invScreenMat = screenMat.map(_.inverse)
  • 50. 50 val screenMat: Signal[Matrix] = (projMat zip viewMat)(_ * _) val invScreenMat = screenMat.map(_.inverse) (4*4*8 + 16 + 16)*4*100 = 64 kb/s
  • 51. 51 val screenMat = Mutable(new Matrix) (projMat, viewMat).mutate(screenMat) { (p, v) => screenMat().assignMul(p, v) } val invScreenMat = Mutable(new Matrix) screenMat.mutate(invScreenMat) { m => invScreenMat().assignInv(m) }
  • 53. 53
  • 54. 54 val selected: Reactive[Set[Character]]
  • 55. 55 val selected: ReactSet[Character]
  • 56. 56 trait ReactSet[T] extends ReactContainer[T] { def apply(x: T): Boolean }
  • 57. 57 trait ReactContainer[T] { def inserts: Reactive[T] def removes: Reactive[T] }
  • 58. 58 A reactive collection is a pair of reactive values
  • 59. 59 val selected = new ReactHashSet[Character]
  • 60. 60
  • 61. 61 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c)))
  • 62. 62 class ReactContainer[T] { self => def inserts: Reactive[T] def removes: Reactive[T] def map[S](f: T => S) = new ReactContainer[S] { def inserts: Reactive[T] = self.inserts.map(f) def removes: Reactive[T] = self.removes.map(f) } }
  • 63. 63 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .to[ReactHashMap]
  • 64. 64 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .to[ReactHashMap]
  • 65. 65 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .to[ReactHashMap]
  • 66. 66 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .to[ReactHashMap]
  • 67. 67 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .react.to[ReactHashMap]
  • 68. 68 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .react.to[ReactHashMap]
  • 69. 69 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .react.to[ReactHashMap]
  • 70. 70 val selected = new ReactHashSet[Character] val decorations = selected .map(c => (c, decoFor(c))) .react.to[ReactHashMap]
  • 72. 72 UI isolate class UI extends Isolate[UI.Message] { val frames = source.filter(_ == UI.Frame) val exit = source onCase { case UI.Exit => exit() } } Source
  • 73. 73 UI Isolate Source AI Isolate Source Channel[AI.Message]   Channel[UI.Message]
  • 74. 74 Reactive collections Isolate Reactive Channel Actor ? ActorRef ? Observable Observable