Await a single value, returning None
if the input has been exhausted.
Behaves like the identity process, but requests n
elements at a time from its input.
Behaves like the identity process, but batches all output into a single Emit
.
Behaves like the identity process, but requests elements from its input in blocks that end whenever the predicate switches from true to false.
Groups inputs into chunks of size n
.
Groups inputs into chunks of size n
. The last chunk may have size
less than n
, depending on the number of elements in the input.
scala> Process(1, 2, 3, 4, 5).chunk(2).toList res0: List[Vector[Int]] = List(Vector(1, 2), Vector(3, 4), Vector(5))
IllegalArgumentException
if n
<= 0
Collects up all output of this Process1
into a single Emit
.
Like chunk
, but emits a chunk whenever the predicate switches from
true to false.
Like chunk
, but emits a chunk whenever the predicate switches from
true to false.
scala> Process(1, 2, -1, 3, 4).chunkBy(_ > 0).toList res0: List[Vector[Int]] = List(Vector(1, 2, -1), Vector(3, 4))
Like chunkBy
, but the predicate depends on the current and previous elements.
Like collect
on scala collection.
Like collect
on scala collection.
Builds a new process by applying a partial function
to all elements of this process on which the function is defined.
Elements, for which the partial function is not defined are filtered out from new process
Like collect
, but emits only the first element of this process on which
the partial function is defined.
Skips the first element that matches the predicate.
Skips the first element that matches the predicate.
scala> Process(3, 4, 5, 6).delete(_ % 2 == 0).toList res0: List[Int] = List(3, 5, 6)
Emits only elements that are distinct from their immediate predecessors.
Emits only elements that are distinct from their immediate predecessors.
scala> import scalaz.std.anyVal._ scala> Process(1, 2, 2, 1, 1, 3).distinctConsecutive.toList res0: List[Int] = List(1, 2, 1, 3)
Emits only elements that are distinct from their immediate predecessors
according to f
.
Emits only elements that are distinct from their immediate predecessors
according to f
.
scala> import scalaz.std.anyVal._ scala> Process("a", "ab", "bc", "c", "d").distinctConsecutiveBy(_.length).toList res0: List[String] = List(a, ab, c)
Remove any leading emitted values that occur before the first successful
Await
.
Remove any leading emitted values that occur before the first successful
Await
. That means that the returned Process1
will produce output only
if it has consumed at least one input element.
Skips the first n
elements of the input, then passes through the rest.
Emits all but the last element of the input.
Emits all elements of the input but skips the last if the predicate is true.
Emits all but the last n
elements of the input.
Skips elements of the input while the predicate is true, then passes through the remaining inputs.
Halts with true
as soon as a matching element is received.
Halts with true
as soon as a matching element is received.
Emits a single false
if no input matches the predicate.
Feed a sequence of inputs to a Process1
.
Feed a single input to a Process1
.
Skips any elements of the input not matching the predicate.
Like filter
, but the predicate f
depends on the previously emitted and
current elements.
Like filter
, but the predicate f
depends on the previously emitted and
current elements.
scala> Process(2, 4, 1, 5, 3).filterBy2(_ < _).toList res0: List[Int] = List(2, 4, 5)
Skips any elements not satisfying predicate and when found, will emit that element and terminate
Process1
form of List.fold
.
Process1
form of List.fold
.
Folds the elements of this Process using the specified associative binary operator.
Unlike List.fold the order is always from the left
side, i.e. it will always
honor order of A
.
If Process of A
is empty, it will just emit z
and terminate
scala> Process(1, 2, 3, 4).fold(0)(_ + _).toList res0: List[Int] = List(10)
Alias for reduce(f)
.
Alias for reduceMap(f)(M)
.
Alias for reduceSemigroup(M)
.
Like fold
only uses f
to map A
to B
and uses Monoid M
for associative operation
Like fold
but uses Monoid for folding operation
Alias for reduceSemigroup(M)
.
Emits a single true
value if all input matches the predicate.
Emits a single true
value if all input matches the predicate.
Halts with false
as soon as a non-matching element is received.
Repeatedly echo the input; satisfies x |> id == x
and id |> x == x
.
Adds separator
between elements of the input.
Adds separator
between elements of the input. For example,
scala> Process(1, 2, 3).intersperse(0).toList res0: List[Int] = List(1, 0, 2, 0, 3)
Skips all but the last element of the input.
Skips all but the last element of the input.
Skips all but the last element of the input.
This Process
will always emit exactly one value;
If the input is empty, li
is emitted.
Transform the input using the given function, f
.
Transform p
to operate on the first element of a pair, passing
through the right value with no modifications.
Transform p
to operate on the first element of a pair, passing
through the right value with no modifications. Note that this halts
whenever p
halts.
function used to convert B
s generated during cleanup of p
to pairs
Transform p
to operate on the left hand side of an \/
, passing
through any values it receives on the right.
Transform p
to operate on the left hand side of an \/
, passing
through any values it receives on the right. Note that this halts
whenever p
halts.
Transform p
to operate on the right hand side of an \/
, passing
through any values it receives on the left.
Transform p
to operate on the right hand side of an \/
, passing
through any values it receives on the left. Note that this halts
whenever p
halts.
Transform p
to operate on the second element of a pair, passing
through the left value with no modifications.
Transform p
to operate on the second element of a pair, passing
through the left value with no modifications. Note that this halts
whenever p
halts.
function used to convert B
s generated during cleanup of p
to pairs
Lifts Process1 to operate on Left side of wye
, ignoring any right input.
Lifts Process1 to operate on Left side of wye
, ignoring any right input.
Use wye.flip
to convert it to right side
Maps a running total according to S
and the input with the function f
.
Maps a running total according to S
and the input with the function f
.
scala> Process("Hello", "World") | .mapAccumulate(0)((l, s) => (l + s.length, s.head)).toList res0: List[(Int, Char)] = List((5,H), (10,W))
Emits the greatest element of the input.
Emits the element a
of the input which yields the greatest value of f(a)
.
Emits the greatest value of f(a)
for each element a
of the input.
Emits the smallest element of the input.
Emits the element a
of the input which yields the smallest value of f(a)
.
Emits the smallest value of f(a)
for each element a
of the input.
Split the input and send to either chanL
or chanR
, halting when
either branch halts.
Split the input and send to either chanL
or chanR
, halting when
either branch halts.
scala> import scalaz.\/._ scala> import process1._ scala> Process(left(1), right('a'), left(2), right('b')) | .pipe(multiplex(lift(_ * -1), lift(_.toInt))).toList res0: List[Int] = List(-1, 97, -2, 98)
Emits the sums of prefixes (running totals) of the input elements.
Emits the sums of prefixes (running totals) of the input elements. The first value emitted will always be zero.
scala> Process(1, 2, 3).prefixSums.toList res0: List[Int] = List(0, 1, 3, 6) scala> Process[Int]().prefixSums.toList res1: List[Int] = List(0)
Process1
form of List.reduce
.
Process1
form of List.reduce
.
Reduces the elements of this Process using the specified associative binary operator.
scala> Process(1, 2, 3, 4).reduce(_ + _).toList res0: List[Int] = List(10) scala> Process(1).reduce(_ + _).toList res1: List[Int] = List(1) scala> Process[Int]().reduce(_ + _).toList res2: List[Int] = List()
Unlike List.reduce
will not fail when Process is empty.
Like reduce
only uses f
to map A
to B
and uses Semigroup M
for
associative operation.
Alias for reduceSemigroup(M)
.
Like reduce
but uses Semigroup M
for associative operation.
Repartitions the input with the function p
.
Repartitions the input with the function p
. On each step p
is applied
to the input and all elements but the last of the resulting sequence
are emitted. The last element is then prepended to the next input using the
Semigroup I
. For example,
scala> import scalaz.std.string._ scala> Process("Hel", "l", "o Wor", "ld").repartition(_.split(" ")).toList res0: List[String] = List(Hello, World)
Repartitions the input with the function p
.
Repartitions the input with the function p
. On each step p
is applied
to the input and the first element of the resulting tuple is emitted if it
is Some(x)
. The second element is then prepended to the next input using
the Semigroup I
. In comparison to repartition
this allows to emit
single inputs without prepending them to the next input.
Throws any input exceptions and passes along successful results.
Similar to List.scan.
Similar to List.scan.
Produces a process of B
containing cumulative results of applying the operator to Process of A
.
It will always emit z
, even when the Process of A
is empty
Similar to scan
, but unlike it it won't emit the z
even when there is no input of A
.
Similar to scan
, but unlike it it won't emit the z
even when there is no input of A
.
scala> Process(1, 2, 3, 4).scan1(_ + _).toList res0: List[Int] = List(1, 3, 6, 10) scala> Process(1).scan1(_ + _).toList res1: List[Int] = List(1) scala> Process[Int]().scan1(_ + _).toList res2: List[Int] = List()
Like scan1
only uses f
to map A
to B
and uses Semigroup M
for
associative operation.
Alias for scanSemigroup(M)
.
Like scan
only uses f
to map A
to B
and uses Monoid M
for associative operation
Like scan
but uses Monoid for associative operation
Like scan1
but uses Semigroup M
for associative operation.
Emit the given values, then echo the rest of the input.
Emit the given values, then echo the rest of the input.
scala> Process(3, 4).shiftRight(1, 2).toList res0: List[Int] = List(1, 2, 3, 4)
Reads a single element of the input, emits nothing, then halts.
Reads a single element of the input, emits nothing, then halts.
scala> import process1._ scala> Process(1, 2, 3).pipe(skip ++ id).toList res0: List[Int] = List(2, 3)
Groups inputs in fixed size chunks by passing a "sliding window"
of size n
over them.
Groups inputs in fixed size chunks by passing a "sliding window"
of size n
over them. If the input contains less than or equal to
n
elements, only one chunk of this size will be emitted.
scala> Process(1, 2, 3, 4).sliding(2).toList res0: List[Vector[Int]] = List(Vector(1, 2), Vector(2, 3), Vector(3, 4))
IllegalArgumentException
if n
<= 0
Break the input into chunks where the delimiter matches the predicate.
Break the input into chunks where the delimiter matches the predicate. The delimiter does not appear in the output. Two adjacent delimiters in the input result in an empty chunk in the output.
Break the input into chunks where the input is equal to the given delimiter.
Break the input into chunks where the input is equal to the given delimiter. The delimiter does not appear in the output. Two adjacent delimiters in the input result in an empty chunk in the output.
Breaks the input into chunks that alternatively satisfy and don't satisfy
the predicate f
.
Breaks the input into chunks that alternatively satisfy and don't satisfy
the predicate f
.
scala> Process(1, 2, -3, -4, 5, 6).splitWith(_ < 0).toList res0: List[Vector[Int]] = List(Vector(1, 2), Vector(-3, -4), Vector(5, 6))
Remove any None
inputs.
Emits the sum of all input elements or zero if the input is empty.
Emits the sum of all input elements or zero if the input is empty.
scala> Process(1, 2, 3).sum.toList res0: List[Int] = List(6) scala> Process[Int]().sum.toList res1: List[Int] = List(0)
Emits all elements of the input except the first one.
Emits all elements of the input except the first one.
scala> Process(1, 2, 3).tail.toList res0: List[Int] = List(2, 3) scala> Process[Int]().tail.toList res1: List[Int] = List()
Passes through n
elements of the input, then halts.
Emits the last n
elements of the input.
Like takeWhile
, but emits the first value which tests false.
Passes through elements of the input as long as the predicate is true, then halts.
Wraps all inputs in Some
, then outputs a single None
before halting.
Ungroups chunked input.
Ungroups chunked input.
scala> Process(Seq(1, 2), Seq(3)).pipe(process1.unchunk).toList res0: List[Int] = List(1, 2, 3)
Zips the input with an index of type N
.
Zips the input with an index of type Int
.
Zips every element with its next element wrapped into Some
.
Zips every element with its next element wrapped into Some
.
The last element is zipped with None
.
Zips every element with its previous element wrapped into Some
.
Zips every element with its previous element wrapped into Some
.
The first element is zipped with None
.
Zips every element with its previous and next elements wrapped into Some
.
Zips every element with its previous and next elements wrapped into Some
.
The first element is zipped with None
as the previous element,
the last element is zipped with None
as the next element.
Zips the input with a running total according to B
, up to but not including the
current element.
Zips the input with a running total according to B
, up to but not including the
current element. Thus the initial z
value is the first emitted to the output:
scala> Process("uno", "dos", "tres", "cuatro").zipWithScan(0)(_.length + _).toList res0: List[(String,Int)] = List((uno,0), (dos,3), (tres,6), (cuatro,10))
Zips the input with a running total according to B
, up to and including the
current element.
Zips the input with a running total according to B
, up to and including the
current element. Thus the initial z
value is not emitted to the output:
scala> Process("uno", "dos", "tres", "cuatro").zipWithScan1(0)(_.length + _).toList res0: List[(String,Int)] = List((uno,3), (dos,6), (tres,10), (cuatro,16))
Zips the input with state that begins with z
and is updated by next
.