ToPull

fs2.Stream.ToPull
final class ToPull[F[_], O] extends AnyVal

Projection of a Stream providing various ways to get a Pull from the Stream.

Attributes

Source
Stream.scala
Graph
Supertypes
class AnyVal
trait Matchable
class Any

Members list

Value members

Concrete methods

def drop(n: Long): Pull[F, Nothing, Option[Stream[F, O]]]

Drops the first n elements of this Stream, and returns the new Stream.

Drops the first n elements of this Stream, and returns the new Stream.

Attributes

Source
Stream.scala
def dropThrough(p: O => Boolean): Pull[F, Nothing, Option[Stream[F, O]]]

Like dropWhile, but drops the first value which tests false.

Like dropWhile, but drops the first value which tests false.

Attributes

Source
Stream.scala
def dropWhile(p: O => Boolean): Pull[F, Nothing, Option[Stream[F, O]]]

Drops elements of the this stream until the predicate p fails, and returns the new stream.

Drops elements of the this stream until the predicate p fails, and returns the new stream. If defined, the first element of the returned stream will fail p.

Attributes

Source
Stream.scala
def echo: Pull[F, O, Unit]

Writes all inputs to the output of the returned Pull.

Writes all inputs to the output of the returned Pull.

Attributes

Source
Stream.scala
def echo1: Pull[F, O, Option[Stream[F, O]]]

Reads a single element from the input and emits it to the output.

Reads a single element from the input and emits it to the output.

Attributes

Source
Stream.scala
def echoChunk: Pull[F, O, Option[Stream[F, O]]]

Reads the next available chunk from the input and emits it to the output.

Reads the next available chunk from the input and emits it to the output.

Attributes

Source
Stream.scala
def fetchN(n: Int): Pull[F, Nothing, Option[Stream[F, O]]]

Like unconsN, but leaves the buffered input unconsumed.

Like unconsN, but leaves the buffered input unconsumed.

Attributes

Source
Stream.scala
def find(f: O => Boolean): Pull[F, Nothing, Option[(O, Stream[F, O])]]

Awaits the next available element where the predicate returns true.

Awaits the next available element where the predicate returns true.

Attributes

Source
Stream.scala
def fold[O2](z: O2)(f: (O2, O) => O2): Pull[F, Nothing, O2]

Folds all inputs using an initial value z and supplied binary operator, and writes the final result to the output of the supplied Pull when the stream has no more values.

Folds all inputs using an initial value z and supplied binary operator, and writes the final result to the output of the supplied Pull when the stream has no more values.

Attributes

Source
Stream.scala
def fold1[O2 >: O](f: (O2, O2) => O2): Pull[F, Nothing, Option[O2]]

Folds all inputs using the supplied binary operator, and writes the final result 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 Pull when the stream has no more values.

Attributes

Source
Stream.scala
def forall(p: O => Boolean): Pull[F, Nothing, Boolean]

Writes a single true value if all input matches the predicate, false otherwise.

Writes a single true value if all input matches the predicate, false otherwise.

Attributes

Source
Stream.scala
def headOrError(implicit F: RaiseThrowable[F]): Pull[F, Nothing, O]

Takes the first value output by this stream and returns it in the result of a pull.

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 NoSuchElementException. If more than 1 value is output, everything beyond the first is ignored.

Attributes

Source
Stream.scala
def last: Pull[F, Nothing, Option[O]]

Returns the last element of the input, if non-empty.

Returns the last element of the input, if non-empty.

Attributes

Source
Stream.scala
def lastOrError(implicit F: RaiseThrowable[F]): Pull[F, Nothing, O]

Returns the last element of the input, if non-empty, otherwise fails the pull with a NoSuchElementException.

Returns the last element of the input, if non-empty, otherwise fails the pull with a NoSuchElementException.

Attributes

Source
Stream.scala
def peek: Pull[F, Nothing, Option[(Chunk[O], Stream[F, O])]]

Like uncons but does not consume the chunk (i.e., the chunk is pushed back).

Like uncons but does not consume the chunk (i.e., the chunk is pushed back).

Attributes

Source
Stream.scala
def peek1: Pull[F, Nothing, Option[(O, Stream[F, O])]]

Like uncons1 but does not consume the element (i.e., the element is pushed back).

Like uncons1 but does not consume the element (i.e., the element is pushed back).

Attributes

Source
Stream.scala
def scanChunks[S, O2](init: S)(f: (S, Chunk[O]) => (S, Chunk[O2])): Pull[F, O2, S]

Like scan but f is applied to each chunk of the source stream.

Like 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.

Attributes

Source
Stream.scala
def scanChunksOpt[S, O2](init: S)(f: S => Option[Chunk[O] => (S, Chunk[O2])]): Pull[F, O2, S]

More general version of scanChunks where the current state (i.e., S) can be inspected to determine if another chunk should be pulled or if the pull should terminate.

More general version of scanChunks where the current state (i.e., S) can be inspected to 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 consumes the next chunk is returned wrapped in Some. The final state value is returned as the result of the pull.

Attributes

Source
Stream.scala
def stepLeg: Pull[F, Nothing, Option[StepLeg[F, O]]]

Like uncons, but instead of performing normal uncons, this will run the stream up to the first chunk available.

Like uncons, but instead of performing normal uncons, this will 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 leg independently of scopes from other legs.

If you are not pulling from multiple streams, consider using uncons.

Attributes

Source
Stream.scala
def take(n: Long): Pull[F, O, Option[Stream[F, O]]]

Emits the first n elements of the input.

Emits the first n elements of the input.

Attributes

Source
Stream.scala
def takeRight(n: Int): Pull[F, Nothing, Chunk[O]]

Emits the last n elements of the input.

Emits the last n elements of the input.

Attributes

Source
Stream.scala
def takeThrough(p: O => Boolean): Pull[F, O, Option[Stream[F, O]]]

Like takeWhile, but emits the first value which tests false.

Like takeWhile, but emits the first value which tests false.

Attributes

Source
Stream.scala
def takeWhile(p: O => Boolean, takeFailure: Boolean): Pull[F, O, Option[Stream[F, O]]]

Emits the elements of the stream until the predicate p fails, and returns the remaining Stream.

Emits the elements of the stream until the predicate p fails, and returns the remaining Stream. If non-empty, the returned stream will have a first element i for which p(i) is false.

Attributes

Source
Stream.scala
def timed[O2, R](pull: Timed[F, O] => Pull[F, O2, R])(implicit F: Temporal[F]): Pull[F, O2, R]

Allows expressing Pull computations whose uncons can receive a user-controlled, resettable timeout.

Allows expressing Pull computations whose uncons can receive a 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 1 second:

Attributes

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](1500.millis)).repeat.take(3)
scala> s.pull
    |  .timed { timedPull =>
    |     def go(timedPull: Pull.Timed[IO, String]): Pull[IO, String, Unit] =
    |       timedPull.timeout(1.second) >> // 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)
Source
Stream.scala
def uncons: Pull[F, Nothing, Option[(Chunk[O], Stream[F, O])]]

Waits for a chunk of elements to be available in the source stream.

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 None is returned as the resource of the pull upon reaching the end of the stream.

Attributes

Source
Stream.scala
def uncons1: Pull[F, Nothing, Option[(O, Stream[F, O])]]

Like uncons but waits for a single element instead of an entire chunk.

Like uncons but waits for a single element instead of an entire chunk.

Attributes

Source
Stream.scala
def unconsLimit(n: Int): Pull[F, Nothing, Option[(Chunk[O], Stream[F, O])]]

Like uncons, but returns a chunk of no more than n elements.

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.

Attributes

Source
Stream.scala
def unconsMin(n: Int, allowFewerTotal: Boolean): Pull[F, Nothing, Option[(Chunk[O], Stream[F, O])]]

Like uncons but returns a chunk of at least n elements, concatenating and splitting as necessary.

Like uncons but returns a chunk of at least n elements, concatenating and splitting as necessary.

Pull.pure(None) is returned if the end of the source stream is reached.

Note: the emitted chunk may be a composite chunk (i.e., an instance of Chunk.Queue) and hence may not have O(1) lookup by index. Consider calling .map(_.compact) if indexed lookup is important.

Attributes

Source
Stream.scala
def unconsN(n: Int, allowFewer: Boolean): Pull[F, Nothing, Option[(Chunk[O], Stream[F, O])]]

Like uncons but returns a chunk of exactly n elements, concatenating and splitting as necessary.

Like uncons but returns a chunk of exactly n elements, concatenating and splitting as necessary.

Pull.pure(None) is returned if the end of the source stream is reached.

Note: the emitted chunk may be a composite chunk (i.e., an instance of Chunk.Queue) and hence may not have O(1) lookup by index. Consider calling .map(_.compact) if indexed lookup is important.

Attributes

Source
Stream.scala