Transformer

trait Transformer[-In, +Out]

Primary "spac" abstraction which represents a transformation stage for a stream of data events

Transformers effectively transform a stream of In events into a stream of Out events. The actual stream handling logic is defined by a Transformer.Handler, which a Transformer is responsible for constructing. Handlers may be internally-mutable, and so they are generally only constructed by other handlers. Transformers themselves are immutable, acting as "handler factories", and so they may be freely reused.

A transformer may choose to abort in response to any input event, as well as emit any number of outputs in response to an input event or the EOF signal.

Type parameters:
In

The incoming event type

Out

The outgoing event type

Companion:
object
class Object
trait Matchable
class Any
trait Stateless[In, Out]
class TransformerCollect[In, Out]
class TransformerMap[A, B]
class TransformerMapFlatten[In, Out]
class TransformerTap[In]
class ParserAsTransformer[In, Out]
class ParserFollowedByTransformer[In, A, Out]
class Boundaries[In, C]
class Boundaries[In, Elem, C]
class Boundaries[In, C]
class SplitterJoiner[In, C, Out]
class TransformerDrop[In]
class TransformerMerge[In, Out]
class TransformerScan[In, Out]
trait TransformerStack[In, Out]
class Head[A, B]
class RCons[A, X, B]
class TransformerTake[In]
class TransformerWithName[In, Out]

Value members

Abstract methods

def newHandler: Handler[In, Out]

Transformer's main abstract method; constructs a new Handler representing this transformer's logic. Transformers are expected to be immutable, but Handlers may be internally-mutable.

Transformer's main abstract method; constructs a new Handler representing this transformer's logic. Transformers are expected to be immutable, but Handlers may be internally-mutable.

Concrete methods

def cast[Out2](implicit ev: Out <:< Out2): Transformer[In, Out2]

Returns this transformer, but with a different view of the Out type. The Out <:< Out2 implicit evidence is used to make sure the asInstanceOf cast is safe. This is mostly useful when you know you have a transformer that yields a tuple or some kind of type constructor.

Returns this transformer, but with a different view of the Out type. The Out <:< Out2 implicit evidence is used to make sure the asInstanceOf cast is safe. This is mostly useful when you know you have a transformer that yields a tuple or some kind of type constructor.

def collect[Out2](pf: PartialFunction[Out, Out2]): Transformer[In, Out2]

Creates a new transformer which filters and maps the outputs from this transformer

Creates a new transformer which filters and maps the outputs from this transformer

Type parameters:
Out2

Result type of the pf

Value parameters:
pf

Partial function responsible for the filtering and mapping of outputs from this transformer

Returns:

The filteried and mapped transformer

def drain: Parser[In, Unit]

Convenience for this into Parser.drain

Convenience for this into Parser.drain

def filter(predicate: Out => Boolean): Transformer[In, Out]

Creates a new transformer which filters the outputs from this transformer.

Creates a new transformer which filters the outputs from this transformer.

Value parameters:
predicate

A function which decides whether an output from this transformer should be emitted from the returned transformer. true means emit, false means skip.

Returns:

The filtered transformer

def into[Out2](parser: Parser[Out, Out2]): Parser[In, Out2]

Attach this transformer to a parser, creating a new parser that encapsulates the pair. Values emitted from this transformer will be passed as inputs to the parser, and the resulting output from the parser will be yielded as output by the combined parser.

Attach this transformer to a parser, creating a new parser that encapsulates the pair. Values emitted from this transformer will be passed as inputs to the parser, and the resulting output from the parser will be yielded as output by the combined parser.

def map[Out2](f: Out => Out2): Transformer[In, Out2]

Creates a new transformer which applies the transformation function f to each of this transformer's outputs.

Creates a new transformer which applies the transformation function f to each of this transformer's outputs.

Type parameters:
Out2

The transformation output type

Value parameters:
f

A transformation function

Returns:

The mapped transformer

def mapFlatten[Out2](f: Out => Iterable[Out2]): Transformer[In, Out2]

Creates a new transformer which transforms the outputs of this transformer via the given function f, emitting each individual value from the output of that function in order before continuing.

Creates a new transformer which transforms the outputs of this transformer via the given function f, emitting each individual value from the output of that function in order before continuing.

Type parameters:
Out2

The transformed output type

Value parameters:
f

A function that transforms outputs from this transformer into a collection of other outputs

Returns:

A new transformer which emits any number of transformed outputs based on outputs from this transformer

def merge[In2 <: In, Out2 >: Out](that: Transformer[In2, Out2]): Transformer[In2, Out2]

Like mergeEither, but when both sides have a common output type. This is a less-roundabout way of doing .mergeEither(right).map(_.merge). The same order-of-operations rules apply as with mergeEither, where this transformer "goes first" for each input.

Like mergeEither, but when both sides have a common output type. This is a less-roundabout way of doing .mergeEither(right).map(_.merge). The same order-of-operations rules apply as with mergeEither, where this transformer "goes first" for each input.

Type parameters:
In2

Contravariance-friendly version of In

Out2

Common output type between this and that

Value parameters:
that

Another transformer

Returns:

The merged transformer

def mergeEither[In2 <: In, Out2](right: Transformer[In2, Out2]): Transformer[In2, Either[Out, Out2]]

Creates a new transformer which sends inputs to both this transformer and the right transformer. Whenever either this or right emit a value, that value will be emitted from the returned transformer, wrapped as a Left or Right depending on which underlying transformer emitted it. For each individual input, the resulting values emitted by this transformer will be emitted before the resulting values emitted by the right transformer.

Creates a new transformer which sends inputs to both this transformer and the right transformer. Whenever either this or right emit a value, that value will be emitted from the returned transformer, wrapped as a Left or Right depending on which underlying transformer emitted it. For each individual input, the resulting values emitted by this transformer will be emitted before the resulting values emitted by the right transformer.

Type parameters:
In2

Contravariance-friendly version of In

Out2

The output type of the right transformer

Value parameters:
right

Another transformer

Returns:

The merged transformer

def parseAsFold[Out2](init: Out2)(f: (Out2, Out) => Out2): Parser[In, Out2]

Convenience for this into Parser.fold(init)(f)

Convenience for this into Parser.fold(init)(f)

def parseFirst(implicit A: TypeName[A]): Parser[In, A]
Implicitly added by TransformerParsingOps

Convenience for this into Parser.first

Convenience for this into Parser.first

def parseFirstOpt: Parser[In, Option[Out]]

Convenience for this into Parser.firstOpt

Convenience for this into Parser.firstOpt

def parseTap(f: Out => Unit): Parser[In, Unit]

Convenience for this into Parser.tap(f)

Convenience for this into Parser.tap(f)

def parseToList: Parser[In, List[Out]]

Convenience for this into Parser.toList

Convenience for this into Parser.toList

def parseToMap: Parser[In, Map[K, V]]
Implicitly added by TransformerKVParsingOps

Convenience for this into Parser.toMap[K, V]

Convenience for this into Parser.toMap[K, V]

def scan[Out2](init: Out2)(op: (Out2, Out) => Out2): Transformer[In, Out2]

Creates a new transformer which folds outputs from this transformer into a "state" which is emitted each time.

Creates a new transformer which folds outputs from this transformer into a "state" which is emitted each time.

Type parameters:
Out2

The type of the scan "state"

Value parameters:
init

The initial "state"

op

State update function; this is called for each Out emitted by this transformer, and the result is emitted by the combined transformer in addition to becoming the next "state"

Returns:

The new transformer

def through[Out2](next: Transformer[Out, Out2]): Transformer[In, Out2]

Attach this transformer to the next transformer, creating a single transformer that encapsulates the pair. Values emitted from this transformer will be passed as inputs to the next transformer, and the resulting outputs from the next transformer are emitted as outputs from the combined transformer.

Attach this transformer to the next transformer, creating a single transformer that encapsulates the pair. Values emitted from this transformer will be passed as inputs to the next transformer, and the resulting outputs from the next transformer are emitted as outputs from the combined transformer.

def transform(itr: Iterator[In])(implicit pos: CallerPos): Iterator[Out]

Applies this transformer's logic to an iterator, returning a new Iterator which yields values emitted by this transformer when run on the underlying itr.

Applies this transformer's logic to an iterator, returning a new Iterator which yields values emitted by this transformer when run on the underlying itr.

Value parameters:
itr

An iterator

Returns:

A wrapped version of itr, transformed via this transformer

def transform(source: Source[In])(implicit pos: CallerPos): Source[Out]

Applies this transformer's logic to a Source, returning a new Source which yields values emitted by this transformer when run on the underlying iterator.

Applies this transformer's logic to a Source, returning a new Source which yields values emitted by this transformer when run on the underlying iterator.

Value parameters:
pos

Captures the call site for the top level SpacTraceElement

source

A Source

Returns:

A wrapped version of source, transformed via this transformer

def upcast[In2 <: In, Out2 >: Out]: Transformer[In2, Out2]

Returns this transformer, but with less restricted In / Out types.

Returns this transformer, but with less restricted In / Out types.

Type parameters:
In2

A subtype of In

Out2

A supertype of Out

Returns:

This transformer (not a copy, it's actually literally this)

def withFilter(predicate: Out => Boolean): Transformer[In, Out]

Alias for filter, used under the hood by for-comprehensions

Alias for filter, used under the hood by for-comprehensions

Value parameters:
predicate

The filtering function

Returns:

The filtered transformer

def withName(name: String): Transformer[In, Out]

Creates a copy of this transformer, but with a different toString

Creates a copy of this transformer, but with a different toString

Value parameters:
name

The new "name" (i.e. toString for this transformer

Returns:

A copy of this transformer whose toString returns the given name

Deprecated methods

@deprecated("Due to troubles with operator precedence and type inference, this operator is being phased out in favor of `through`", "v0.9")
def >>[Out2](next: Transformer[Out, Out2]): Transformer[In, Out2]
Deprecated
@deprecated("Due to troubles with operator precedence and type inference, this operator is being phased out in favor of `into`", "v0.9")
def >>[Out2](parser: Parser[Out, Out2]): Parser[In, Out2]
Deprecated
@deprecated("This method is being renamed to `through`", "v0.9")
def andThen[Out2](next: Transformer[Out, Out2]): Transformer[In, Out2]
Deprecated
@deprecated("This method is being renamed to `merge`", "v0.9")
def parallel[In2 <: In, Out2 >: Out](that: Transformer[In2, Out2]): Transformer[In2, Out2]
Deprecated
@deprecated("This method is being renamed to `mergeEither`", "v0.9")
def parallelEither[In2 <: In, Out2](right: Transformer[In2, Out2]): Transformer[In2, Either[Out, Out2]]
Deprecated
@deprecated("This method is being renamed to `parseFirstOpt`", "v0.9")
def parseFirstOption: Parser[In, Option[Out]]
Deprecated
@deprecated("This method is being renamed to `parseTap`", "v0.9")
def parseForeach(f: Out => Any): Parser[In, Unit]
Deprecated
@deprecated("Use `into` instead", "v0.9")
def parseWith[Out2](parser: Parser[Out, Out2]): Parser[In, Out2]
Deprecated
@deprecated("Use the single-argument version of `into`, then call `withName` on the resulting parser", "v0.9")
def parseWith[Out2](parser: Parser[Out, Out2], setDebugName: Option[String]): Parser[In, Out2]
Deprecated
@deprecated("This method is being renamed to `drain`", "v0.9")
def sink: Parser[In, Unit]
Deprecated