Scan

fs2.Scan
See theScan companion object
final class Scan[S, -I, +O](val initial: S, transform_: AndThen[(S, I), (S, Chunk[O])], onComplete_: AndThen[S, Chunk[O]])

A stateful transformation of the elements of a stream.

A scan is primarily represented as a function (S, I) => (S, Chunk[O]). Scans also have an initial state value of type S and the ability to emit elements upon completion via a function S => Chunk[O].

A scan is built up incrementally via various combinators and then converted to a pipe via .toPipe. For example, s.through(Scan.lift(identity).toPipe) == s.

A scan is much less powerful than a pull. Scans cannot evaluate effects or terminate early. These limitations allow combinators that are not possible on pulls though. For example, the first method converts a Scan[S, I, O] to a Scan[S, (I, A), (O, A)]. Critically, this method relies on the ability to feed a single I to the original scan and collect the resulting O values, pairing each O with the A that was paired with I.

Attributes

Companion
object
Source
Scan.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def andThen[S2, O2](that: Scan[S2, O, O2]): Scan[(S, S2), I, O2]

Composes the supplied scan with this scan.

Composes the supplied scan with this scan.

The resulting scan maintains the state of each of the input scans independently.

Attributes

Source
Scan.scala
def choice[S2, I2, O2 >: O](that: Scan[S2, I2, O2]): Scan[(S, S2), Either[I, I2], O2]

Combines this scan with the supplied scan such that elements on the left are fed through this scan while elements on the right are fed through the suppplied scan. The outputs are joined together.

Combines this scan with the supplied scan such that elements on the left are fed through this scan while elements on the right are fed through the suppplied scan. The outputs are joined together.

Attributes

Source
Scan.scala
def choose[S2, I2, O2](t: Scan[S2, I2, O2]): Scan[(S, S2), Either[I, I2], Either[O, O2]]

Like choice but the output elements are kept separate.

Like choice but the output elements are kept separate.

Attributes

Source
Scan.scala
def contramap[I2](f: I2 => I): Scan[S, I2, O]

Returns a new scan which transforms input values using the supplied function.

Returns a new scan which transforms input values using the supplied function.

Attributes

Source
Scan.scala
def dimap[I2, O2](g: I2 => I)(f: O => O2): Scan[S, I2, O2]

Attributes

Source
Scan.scala
def first[A]: Scan[S, (I, A), (O, A)]

Returns a scan that inputs/outputs pairs of elements, with I and O in the first element of the pair.

Returns a scan that inputs/outputs pairs of elements, with I and O in the first element of the pair.

Attributes

Source
Scan.scala
def imapState[S2](g: S => S2)(f: S2 => S): Scan[S2, I, O]

Transforms the state type.

Transforms the state type.

Attributes

Source
Scan.scala
def left[A]: Scan[S, Either[I, A], Either[O, A]]

Returns a scan that wraps the inputs/outputs with Either. Elements on the left pass through the original scan while elements on the right pass through directly.

Returns a scan that wraps the inputs/outputs with Either. Elements on the left pass through the original scan while elements on the right pass through directly.

Attributes

Source
Scan.scala
def lens[I2, O2](get: I2 => I, set: (I2, O) => O2): Scan[S, I2, O2]

Returns a new scan with transformed input and output types.

Returns a new scan with transformed input and output types.

Upon receiving an I2, get is invoked and the result is fed to the original scan. For each output value, set is invoked with the original I2 input and the computed O, yielding a new output of type O2.

Attributes

Source
Scan.scala
def map[O2](f: O => O2): Scan[S, I, O2]

Returns a new scan which transforms output values using the supplied function.

Returns a new scan which transforms output values using the supplied function.

Attributes

Source
Scan.scala
def onComplete(s: S): Chunk[O]

Completion function.

Completion function.

Attributes

Source
Scan.scala
def right[A]: Scan[S, Either[A, I], Either[A, O]]

Returns a scan that wraps the inputs/outputs with Either. Elements on the right pass through the original scan while elements on the left pass through directly.

Returns a scan that wraps the inputs/outputs with Either. Elements on the right pass through the original scan while elements on the left pass through directly.

Attributes

Source
Scan.scala
def second[A]: Scan[S, (A, I), (A, O)]

Returns a scan that inputs/outputs pairs of elements, with I and O in the second element of the pair.

Returns a scan that inputs/outputs pairs of elements, with I and O in the second element of the pair.

Attributes

Source
Scan.scala
def semilens[I2, O2](extract: I2 => Either[O2, I], inject: (I2, O) => O2): Scan[S, I2, O2]

Like lens but some elements are passed to the output (skipping the original scan) while other elements are lensed through the original scan.

Like lens but some elements are passed to the output (skipping the original scan) while other elements are lensed through the original scan.

Attributes

Source
Scan.scala
def semipass[I2, O2 >: O](extract: I2 => Either[O2, I]): Scan[S, I2, O2]

Like semilens but the elements of the original scan are output directly.

Like semilens but the elements of the original scan are output directly.

Attributes

Source
Scan.scala
def step(i: I): (Scan[S, I, O], Chunk[O])

Steps this scan by a single input, returning a new scan and the output elements computed from the input.

Steps this scan by a single input, returning a new scan and the output elements computed from the input.

Attributes

Source
Scan.scala
def toPipe[F[_]]: Stream[F, I] => Stream[F, O]

Converts this scan to a pipe.

Converts this scan to a pipe.

Attributes

Source
Scan.scala
def transform(s: S, i: I): (S, Chunk[O])

Transformation function.

Transformation function.

Attributes

Source
Scan.scala
def transformAccumulate(s: S, c: Chunk[I]): (S, Chunk[O])

Chunk form of transform.

Chunk form of transform.

Attributes

Source
Scan.scala

Concrete fields

val initial: S

Attributes

Source
Scan.scala