fs2
package fs2
- Source
- fs2.scala
- Alphabetic
- By Inheritance
- fs2
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
Chunk
[+A] extends AnyRef
A strict, in-memory sequence of
A
values. -
final
class
Handle
[+F[_], +A] extends AnyRef
A currently open
Stream[F,A]
, allowing chunks to be pulled or pushed. -
sealed
trait
NonEmptyChunk
[+A] extends Chunk[A]
A chunk which has at least one element.
-
type
Pipe[F[_], -I, +O] = (Stream[F, I]) ⇒ Stream[F, O]
A pipe is a stream transformation, represented as a function from stream to stream.
A pipe is a stream transformation, represented as a function from stream to stream.
Pipes are typically applied with the
through
operation onStream
. -
type
Pipe2[F[_], -I, -I2, +O] = (Stream[F, I], Stream[F, I2]) ⇒ Stream[F, O]
A
Pipe2
is a stream transformation that combines two streams in to a single stream, represented as a function from stream to stream.A
Pipe2
is a stream transformation that combines two streams in to a single stream, represented as a function from stream to stream.Pipe2
s are typically applied with thethrough2
operation onStream
. -
final
class
Pull
[+F[_], +O, +R] extends AnyRef
A pull allows acquiring elements from a stream in a resource safe way, emitting elements of type
O
, working with a resource of typeR
, and evaluating effects of typeF
.A pull allows acquiring elements from a stream in a resource safe way, emitting elements of type
O
, working with a resource of typeR
, and evaluating effects of typeF
.Laws:
or
forms a monoid in conjunction withdone
:or(done, p) == p
andor(p, done) == p
.or(or(p1,p2), p3) == or(p1, or(p2,p3))
fail
is caught byonError
:onError(fail(e))(f) == f(e)
Pull
forms a monad withpure
andflatMap
:pure >=> f == f
f >=> pure == f
(f >=> g) >=> h == f >=> (g >=> h)
wheref >=> g
is defined asa => a flatMap f flatMap g
-
sealed
trait
Pure
[+A] extends AnyRef
Marker trait.
Marker trait. A
Stream[Pure,O]
can be safely cast to aStream[Nothing,O]
, but theStream[Pure,O]
has better type inference properties in some places. See usage inStream.pull
. -
trait
Scheduler
extends AnyRef
Provides the ability to schedule evaluation of thunks in the future.
- final class Scope [+F[_], +O] extends AnyRef
-
sealed
trait
ScopedFuture
[F[_], A] extends AnyRef
Future that evaluates to a value of type
A
and aScope[F,Unit]
.Future that evaluates to a value of type
A
and aScope[F,Unit]
.To use a
Future
, convert to aPull
(viaf.pull
) or aStream
(viaf.stream
). -
type
Sink[F[_], -I] = (Stream[F, I]) ⇒ Stream[F, Unit]
A sink is a pipe that converts a stream to a
Stream[F,Unit]
.A sink is a pipe that converts a stream to a
Stream[F,Unit]
.Sinks are typically applied with the
to
operation onStream
. -
trait
Strategy
extends AnyRef
Provides a function for evaluating thunks, possibly asynchronously.
-
final
class
Stream
[+F[_], +O] extends AnyRef
A stream producing output of type
O
, which may evaluateF
effects.A stream producing output of type
O
, which may evaluateF
effects. IfF
isNothing
orfs2.Pure
, the stream is pure.Laws (using infix syntax):
append
forms a monoid in conjunction withempty
:empty append s == s
ands append empty == s
. -(s1 append s2) append s3 == s1 append (s2 append s3)
And
push
is consistent with usingappend
to prepend a single chunk: -push(c)(s) == chunk(c) append s
fail
propagates until being caught byonError
:fail(e) onError h == h(e)
fail(e) append s == fail(e)
fail(e) flatMap f == fail(e)
Stream
forms a monad withemit
andflatMap
:emit >=> f == f
f >=> emit == f
(f >=> g) >=> h == f >=> (g >=> h)
whereemit(a)
is defined aschunk(Chunk.singleton(a)) and
f >=> gis defined as
a => a flatMap f flatMap g
The monad is the list-style sequencing monad:
(a append b) flatMap f == (a flatMap f) append (b flatMap f)
empty flatMap f == empty
-
class
Task
[+A] extends AnyRef
Task
is a trampolined computation producing anA
that may include asynchronous steps.Task
is a trampolined computation producing anA
that may include asynchronous steps. Arbitrary monadic expressions involvingmap
andflatMap
are guaranteed to use constant stack space. In addition, usingTask.async
, one may construct aTask
from callback-based APIs. This makesTask
useful as a concurrency primitive and as a control structure for wrapping callback-based APIs with a more straightforward, monadic API.Task is also exception-safe. Any exceptions raised during processing may be accessed via the
attempt
method, which converts aTask[A]
to aTask[Attempt[A]]
.Unlike the
scala.concurrent.Future
type introduced in scala 2.10,map
andflatMap
do NOT spawn new tasks and do not require an implicitExecutionContext
. Instead,map
andflatMap
merely add to the current (trampolined) continuation that will be run by the 'current' thread, unless explicitly forked viaTask.start
orFuture.apply
. This means thatFuture
achieves much better thread reuse than the 2.10 implementation and avoids needless thread pool submit cycles.Task
also differs from thescala.concurrent.Future
type in that it does not represent a _running_ computation. Instead, we reintroduce concurrency _explicitly_ using theTask.start
function. This simplifies our implementation and makes code easier to reason about, since the order of effects and the points of allowed concurrency are made fully explicit and do not depend on Scala's evaluation order.