Skip to content

PullOps<O>

extensionPullOps<O>onPull<O,Unit>

Operations available ONLY when the result type is Unit. This ensures we can only inspect a "streaming" pull, not a calculated result.

Properties

rill extension no setter

Rill<O>getrill

Converts this Pull into a Rill wrapped in its own Scope.

Available on Pull<O, R>, provided by the PullOps<O> extension

Implementation
dart
Rill<O> get rill => Rill._scoped(this);

rillNoScope extension no setter

Rill<O>getrillNoScope

Converts this Pull into a Rill without introducing a new Scope.

Use when the pull is already scoped (e.g. inside a Rill.bracketFull).

Available on Pull<O, R>, provided by the PullOps<O> extension

Implementation
dart
Rill<O> get rillNoScope => Rill._noScope(this);

uncons extension no setter

Pull<Never,Option<Record>>getuncons

Peels off the next chunk of the current pull.

Returns a Pull that emits nothing, but evaluates to an Option containing:

Available on Pull<O, R>, provided by the PullOps<O> extension

Implementation
dart
Pull<Never, Option<(Chunk<O>, Pull<O, Unit>)>> get uncons {
  return Pull.getScope.flatMap((scope) {
    return Pull.eval(_stepPull(this, scope)).flatMap((step) {
      return switch (step) {
        final _StepDone<dynamic, dynamic> _ => Pull.pure(none()),
        final _StepOut<O, Unit> _ => Pull.pure(Some((step.head, step.next))),
        final _StepError<dynamic, dynamic> step => Pull.raiseError(step.error, step.stackTrace),
      };
    });
  });
}

Methods

flatMapOutput() extension

Pull<O2,Unit>flatMapOutput<O2>(Pull<O2,Unit>Function(O)f)

Processes each output element through f, emitting the resulting pulls in sequence and merging their outputs into the stream.

Available on Pull<O, R>, provided by the PullOps<O> extension

Implementation
dart
Pull<O2, Unit> flatMapOutput<O2>(Function1<O, Pull<O2, Unit>> f) {
  return Pull.getScope.flatMap((scope) {
    return Pull.eval(_stepPull(this, scope)).flatMap((step) {
      switch (step) {
        case final _StepDone<O, Unit> _:
          return Pull.pure<Unit>(step.result);
        case _StepOut<O, Unit> _:
          final head = step.head;
          final next = step.next;

          Pull<O2, Unit> runChunk(Chunk<O> chunk) {
            if (chunk.isEmpty) {
              return Pull.done;
            } else {
              return f(chunk.head).flatMap((_) => runChunk(chunk.tail));
            }
          }

          return runChunk(head).flatMap((_) => next.flatMapOutput(f));
        case final _StepError<dynamic, dynamic> s:
          return Pull.raiseError(s.error, s.stackTrace);
      }
    });
  });
}

unconsFlatMap() extension

Pull<O2,Unit>unconsFlatMap<O2>(Pull<O2,Unit>Function(Chunk<O>)f,);

Repeatedly peels off the next chunk and passes it to f, concatenating the resulting pulls until the stream is exhausted.

Available on Pull<O, R>, provided by the PullOps<O> extension

Implementation
dart
Pull<O2, Unit> unconsFlatMap<O2>(Function1<Chunk<O>, Pull<O2, Unit>> f) {
  return uncons.flatMap<O2, Unit>((hdtl) {
    return hdtl.foldN<Pull<O2, Unit>>(
      () => Pull.done,
      (hd, tl) => f(hd).append<O2, Unit>(() => tl.unconsFlatMap(f)),
    );
  });
}