Streaming libraries are kind of complex. Why is that so?
They have to handle many different concerns: streaming, composition, concurrency, resources management,... Is it possible to isolate those concerns into smaller, composable libraries?
17. 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
18. 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
19. 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]
23. 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'
24.
25. The design goals are
• compositionality
• expressiveness
• resource safety
• speed
26. 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
29. 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
35. 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