SlideShare uma empresa Scribd logo
1 de 109
Baixar para ler offline
Streams, effects
and
Beautiful folds
Eric Torreborre
About Zalando
Every application ever
written can be viewed
as some sort of
transformation on data.
Daniel Spiewak
???
Streams!
or iteratees...
or observables...
data ConduitM i o m r
This type represents a general component which can
• consume a stream of input values i
• produce a stream of output values o
• perform actions in the m monad
• and produce a final result r
type Pipe a b = Proxy () a () b
A Proxy is a monad transformer that receives and
sends information on both an upstream and
downstream interface
data Proxy a' a b' b m r
Machines are demand-driven coroutines ... they are entirely pure.
A Machine can be driven by a Driver which can have effects when
feeding the Machine input or when reading its output
• you can construct a `Plan` and then `compile` it to a `Machine`
• a `Plan[K, O, A]` is a specification for a pure `Machine` that reads inputs
selected by `K` and writes values of type `O`
• the `Plan` has intermediate results of type `A` which are placeholders for further
plans
trait Plan[+K, +O, +A]
type Machine[+K, +O] =
Plan[K, O, Nothing]
Motivation
• data too large
• actors offer no static guarantee
• back-pressure
class Flow[-In, +Out, +Mat](m: Module)
extends Graph[FlowShape[In, Out], Mat]
A Flow is a set of stream processing steps that has one
open input and one open output.
Materialized: 'a value that can be obtained from the
materialized processing pipeline'
The design goals are
• compositionality
• expressiveness
• resource safety
• speed
StreamCore / Stack
Segment (Fail, Emit, Handler, Append)
Scope
Chunk / Pull
Stream[+F[_],+O](core: CoreRef[F,O])
A stream producing output of type `O` and which may
evaluate `F` effects
Motivation
• high-performance
• lightweight
• conceptually simple
• debuggable
• type-safe and concise
class Pipe[-A, +B] extends StreamOps[B]
Simple transformations are stream graph components with
one input port and one output port
trait StreamOps[A] {
type Repr[T] <:
StreamOps[T] {
type Repr[X] <: self.Repr[X]
}
}
}
FanIn, Spout, shapeless
Motivation
• resource management
• streaming
• fusion
• error recovery
• not for concurrency
Motivation
• asynchronous
• reactive
• streaming
• back-pressure
class Observable[A]
class Consumer[A, B] extends
(Observable[A] => Task[B])
• Observable implements the "Reactive Pattern" = subscribe
Subscribers
• Consumer is a specification of how to consume an
Observable to return a result
Differences?
Streaming
Composition
Safety
Concurrency
Backpressure
Topology
Producer
EffectsFolds
Streaming
Composition
Backpressure
...
Create
Transform
Monad
Transform
Nice way to
the room?
Run
Streaming
Composition
Backpressure
Streaming
Composition
Topology
def count():
current = 0
while True:
(yield current)
current = current + 1
c = count()
next(c)
print(c.send(1)) // 1
print(c.send(1)) // 2
print(c.send(1)) // 3
c.close()
Run
Folds
count
minimum
maximum
all any
headlast
firstN
lastN plus
times
varianceaverage
quantiles countMinSketch
Applicative
Topology
Sinks
Streaming
Composition
Topology
Safety
Concurrency
Backpressure
TimedFutureEffect
TaskEffect
TaskEffect
TwitterFutureEffect
TaskEffect
Short-circuit
Safety
Safety
Concurrency
Backpressure
Backpressure
Merging queues
Producer
EffectsFolds
tricky
Producer
Fold
Safe?
Safe Producer
tricky II
Streaming, effects and beautiful folds: a winning trilogy

Mais conteúdo relacionado

Mais procurados

Reactive cocoa 101改
Reactive cocoa 101改Reactive cocoa 101改
Reactive cocoa 101改
Jeff Lee
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
poonam.rwalia
 

Mais procurados (16)

Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
 
Guide lines for drawing flow charts
Guide lines for drawing flow chartsGuide lines for drawing flow charts
Guide lines for drawing flow charts
 
PLA
PLAPLA
PLA
 
Reactive cocoa 101改
Reactive cocoa 101改Reactive cocoa 101改
Reactive cocoa 101改
 
Simulink Projects Research Help
Simulink Projects Research HelpSimulink Projects Research Help
Simulink Projects Research Help
 
Ch02
Ch02Ch02
Ch02
 
Simulink
SimulinkSimulink
Simulink
 
Getting More for Less in Optimized MapReduce Workflows
Getting More for Less in Optimized MapReduce WorkflowsGetting More for Less in Optimized MapReduce Workflows
Getting More for Less in Optimized MapReduce Workflows
 
Discrete Math Lab Cheminformatics Joint Project
Discrete Math Lab Cheminformatics Joint ProjectDiscrete Math Lab Cheminformatics Joint Project
Discrete Math Lab Cheminformatics Joint Project
 
Simulation lab
Simulation labSimulation lab
Simulation lab
 
Ppt 2 d ploting k10998
Ppt 2 d ploting k10998Ppt 2 d ploting k10998
Ppt 2 d ploting k10998
 
Chapter 02 - Problem Solving
Chapter 02 - Problem SolvingChapter 02 - Problem Solving
Chapter 02 - Problem Solving
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Working with Simulink
Working with SimulinkWorking with Simulink
Working with Simulink
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 

Semelhante a Streaming, effects and beautiful folds: a winning trilogy

FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
DeepasCSE
 

Semelhante a Streaming, effects and beautiful folds: a winning trilogy (20)

Functional Scala
Functional ScalaFunctional Scala
Functional Scala
 
Intro to Akka Streams
Intro to Akka StreamsIntro to Akka Streams
Intro to Akka Streams
 
Computer programming and utilization
Computer programming and utilizationComputer programming and utilization
Computer programming and utilization
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Rseminarp
RseminarpRseminarp
Rseminarp
 
Slicing of Object-Oriented Programs
Slicing of Object-Oriented ProgramsSlicing of Object-Oriented Programs
Slicing of Object-Oriented Programs
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
C language
C languageC language
C language
 
Netflix Machine Learning Infra for Recommendations - 2018
Netflix Machine Learning Infra for Recommendations - 2018Netflix Machine Learning Infra for Recommendations - 2018
Netflix Machine Learning Infra for Recommendations - 2018
 
ML Infra for Netflix Recommendations - AI NEXTCon talk
ML Infra for Netflix Recommendations - AI NEXTCon talkML Infra for Netflix Recommendations - AI NEXTCon talk
ML Infra for Netflix Recommendations - AI NEXTCon talk
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C Language
 
EST 102 Programming in C-MODULE 4
EST 102 Programming in C-MODULE 4EST 102 Programming in C-MODULE 4
EST 102 Programming in C-MODULE 4
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
C++ Ch3
C++ Ch3C++ Ch3
C++ Ch3
 
C
CC
C
 

Mais de Eric Torreborre

Mais de Eric Torreborre (20)

wire-all-the-things-lambda-days-2023.pdf
wire-all-the-things-lambda-days-2023.pdfwire-all-the-things-lambda-days-2023.pdf
wire-all-the-things-lambda-days-2023.pdf
 
The many faces of modularity
The many faces of modularityThe many faces of modularity
The many faces of modularity
 
What haskell taught us when we were not looking
What haskell taught us when we were not lookingWhat haskell taught us when we were not looking
What haskell taught us when we were not looking
 
Wire once, rewire twice! (Haskell exchange-2018)
Wire once, rewire twice! (Haskell exchange-2018)Wire once, rewire twice! (Haskell exchange-2018)
Wire once, rewire twice! (Haskell exchange-2018)
 
Pratical eff-functional-conf
Pratical eff-functional-confPratical eff-functional-conf
Pratical eff-functional-conf
 
Specs2, from starters to dessert and... a look in the kitchen
Specs2, from starters to dessert and... a look in the kitchenSpecs2, from starters to dessert and... a look in the kitchen
Specs2, from starters to dessert and... a look in the kitchen
 
Pratical eff-scalaitaly-2017
Pratical eff-scalaitaly-2017Pratical eff-scalaitaly-2017
Pratical eff-scalaitaly-2017
 
Pratical eff monad at Scaladays Chicago
Pratical eff monad at Scaladays ChicagoPratical eff monad at Scaladays Chicago
Pratical eff monad at Scaladays Chicago
 
Pratical eff
Pratical effPratical eff
Pratical eff
 
The Eff monad, one monad to rule them all
The Eff monad, one monad to rule them allThe Eff monad, one monad to rule them all
The Eff monad, one monad to rule them all
 
Easy di-slideshare
Easy di-slideshareEasy di-slideshare
Easy di-slideshare
 
Data generation, the hard parts
Data generation, the hard partsData generation, the hard parts
Data generation, the hard parts
 
Origami, a monadic fold library for Scala
Origami, a monadic fold library for ScalaOrigami, a monadic fold library for Scala
Origami, a monadic fold library for Scala
 
Datatypes for the real world
Datatypes for the real worldDatatypes for the real world
Datatypes for the real world
 
Specs2 3.4
Specs2 3.4Specs2 3.4
Specs2 3.4
 
DSLs with fold algebras
DSLs with fold algebrasDSLs with fold algebras
DSLs with fold algebras
 
Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014
 
Epic success \/ failure, refactoring to *real* FP
Epic success \/ failure, refactoring to *real* FPEpic success \/ failure, refactoring to *real* FP
Epic success \/ failure, refactoring to *real* FP
 
Vampire methods
Vampire methodsVampire methods
Vampire methods
 
Specs2 whirlwind-tour
Specs2 whirlwind-tourSpecs2 whirlwind-tour
Specs2 whirlwind-tour
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Streaming, effects and beautiful folds: a winning trilogy