Splitter

trait Splitter[In, +C]

Primary "spac" abstraction that acts as a selector for sub-streams within a single input stream.

A "sub-stream" is some series of consecutive values from the original stream, identified by a "context" value. Sub-streams do not overlap with each other.

For example, when handling a stream of XML events, you might want to create a Splitter that identifies the events representing elements at a specific location within the XML; something like an XPATH that operates on streams. When using xml-spac, you might construct a splitter like Splitter.xml("rootElem" \ "things" \ "thing"). This would identify a new sub-stream for each <thing> element that appears inside a <things> element, inside the <rootElem> element. An example sub-stream for a <thing> element might be ElemStart("thing"), Text("hello"), ElemEnd("thing").

A Splitter's general goal is to attach a Parser or Transformer to each sub-stream, passing the contents of that sub-stream through the attached Parser or Transformer in order to get an interpretation of that sub-stream (i.e. the Parser's result, or some emitted outputs from a Transformer). With the <thing> example above, you might attach a parser that concatenates the context all Text events it sees. I.e. XmlParser.forText. Since a separate parser handler will run for each sub-stream, this becomes something like "A stream of Strings which each represent the concatenated text from an individual <thing> element".

Type parameters:
C

Context type used to identify each sub-stream

In

Data event type for the input stream

Companion:
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def addBoundaries: Transformer[In, Either[ContextChange[In, C], In]]

Inject "boundary" events into an input stream, where a ContextPush represents the beginning of a new sub-stream, and a ContextPop represents the end of a sub-stream.

Inject "boundary" events into an input stream, where a ContextPush represents the beginning of a new sub-stream, and a ContextPop represents the end of a sub-stream.

Returns:

A transformer that injects the boundary events into any given input stream

Concrete methods

def as[Out](implicit parser: Parser[In, Out]): Transformer[In, Out]

Like joinBy, but the parser is passed implicitly

Like joinBy, but the parser is passed implicitly

def flatMap[Out](transformMatches: ContextPush[In, C] => Transformer[In, Out]): Transformer[In, Out]

Creates a new transformer by attaching an "inner" transformer to each sub-stream based on the sub-stream context. For each sub-stream, a new transformer will be created, and the inputs from the sub-stream will be piped into the inner transformer. Anything that the inner transformer emits will be emitted by the returned transformer.

Creates a new transformer by attaching an "inner" transformer to each sub-stream based on the sub-stream context. For each sub-stream, a new transformer will be created, and the inputs from the sub-stream will be piped into the inner transformer. Anything that the inner transformer emits will be emitted by the returned transformer.

def joinBy[Out](parser: Parser[In, Out]): Transformer[In, Out]

Like map, but when you want to use the same parser for each sub-stream, regardless of the context value

Like map, but when you want to use the same parser for each sub-stream, regardless of the context value

def map[Out](parseMatches: C => Parser[In, Out]): Transformer[In, Out]

Creates a new transformer by attaching a new parser to each sub-stream based on the sub-stream context. For each sub-stream, a new parser will be created, and inputs from the sub-stream will be piped into that parser. When the sub-stream ends, or if the parser finishes on its own, the parser's result will be emitted as an Out event.

Creates a new transformer by attaching a new parser to each sub-stream based on the sub-stream context. For each sub-stream, a new parser will be created, and inputs from the sub-stream will be piped into that parser. When the sub-stream ends, or if the parser finishes on its own, the parser's result will be emitted as an Out event.

Type parameters:
Out

The parser's output type

Value parameters:
parseMatches

Given the context for a sub-stream, return a parser to handle that sub-stream

Returns:

A transformer that will emit the result of each parsed sub-stream

def mapTraced[Out](parseMatches: ContextPush[In, C] => Parser[In, Out]): Transformer[In, Out]

Like map, but using the ContextPush associated with the sub-stream, instead of just the context value itself.

Like map, but using the ContextPush associated with the sub-stream, instead of just the context value itself.