ToPull
Projection of a
Stream
providing various ways to get a Pull
from the Stream
.class AnyVal
trait Matchable
class Any
Value members
Methods
Waits for a chunk of elements to be available in the source stream.
The ''non-empty''' chunk of elements along with a new stream are provided as the resource of the returned pull.
The new stream can be used for subsequent operations, like awaiting again.
A
The ''non-empty''' chunk of elements along with a new stream are provided as the resource of the returned pull.
The new stream can be used for subsequent operations, like awaiting again.
A
None
is returned as the resource of the pull upon reaching the end of the stream.Like uncons, but returns a chunk of no more than
n
elements.Pull.pure(None)
is returned if the end of the source stream is reached.Like uncons, but returns a chunk of exactly
n
elements, splitting chunk as necessary.Pull.pure(None)
is returned if the end of the source stream is reached.Drops elements of the this stream until the predicate
If defined, the first element of the returned stream will fail
p
fails, and returns the new stream.If defined, the first element of the returned stream will fail
p
.Takes the first value output by this stream and returns it in the result of a pull.
If no value is output before the stream terminates, the pull is failed with a
If more than 1 value is output, everything beyond the first is ignored.
If no value is output before the stream terminates, the pull is failed with a
NoSuchElementException
.If more than 1 value is output, everything beyond the first is ignored.
Folds all inputs using an initial value
result to the output of the supplied
z
and supplied binary operator, and writes the finalresult to the output of the supplied
Pull
when the stream has no more values.Folds all inputs using the supplied binary operator, and writes the final result to the output of
the supplied
the supplied
Pull
when the stream has no more values.Returns the last element of the input, if non-empty, otherwise fails the pull with a
NoSuchElementException
.Like
The resulting chunk is emitted while the resulting state is used in the
next invocation of
scan
but f
is applied to each chunk of the source stream.The resulting chunk is emitted while the resulting state is used in the
next invocation of
f
. The final state value is returned as the result of the pull.More general version of
to determine if another chunk should be pulled or if the pull should terminate.
Termination is signaled by returning
the next chunk is returned wrapped in
result of the pull.
scanChunks
where the current state (i.e., S
) can be inspectedto determine if another chunk should be pulled or if the pull should terminate.
Termination is signaled by returning
None
from f
. Otherwise, a function which consumesthe next chunk is returned wrapped in
Some
. The final state value is returned as theresult of the pull.
Like
run the stream up to the first chunk available.
Useful when zipping multiple streams (legs) into one stream.
Assures that scopes are correctly held for each stream
independently of scopes from other legs.
uncons
, but instead of performing normal uncons
, this willrun the stream up to the first chunk available.
Useful when zipping multiple streams (legs) into one stream.
Assures that scopes are correctly held for each stream
leg
independently of scopes from other legs.
If you are not pulling from multiple streams, consider using
uncons
.Emits the elements of the stream until the predicate
and returns the remaining
a first element
p
fails,and returns the remaining
Stream
. If non-empty, the returned stream will havea first element
i
for which p(i)
is false
.Allows expressing
a user-controlled, resettable
See Pull.Timed for more info on timed
Pull
computations whose uncons
can receivea user-controlled, resettable
timeout
.See Pull.Timed for more info on timed
uncons
and timeout
.As a quick example, let's write a timed pull which emits the
string "late!" whenever a chunk of the stream is not emitted
within 150 milliseconds:
string "late!" whenever a chunk of the stream is not emitted
within 150 milliseconds:
- Example
- {{{
scala> import cats.effect.IO
scala> import cats.effect.unsafe.implicits.global
scala> import scala.concurrent.duration._
scala> val s = (Stream("elem") ++ Stream.sleep_IO).repeat.take(3)
scala> s.pull
| .timed { timedPull =>
| def go(timedPull: Pull.Timed[IO, String] ): Pull[IO, String, Unit] =
| timedPull.timeout(150.millis) >> // starts new timeout and stops the previous one
| timedPull.uncons.flatMap {
| case Some((Right(elems), next)) => Pull.output(elems) >> go(next)
| case Some((Left(_), next)) => Pull.output1("late!") >> go(next)
| case None => Pull.done
| }
| go(timedPull)
| }.stream.compile.toVector.unsafeRunSync()
res0: Vector[String] = Vector(elem, late!, elem, late!, elem)
}}}
For a more complex example, look at the implementation of Stream.groupWithin.