Skip to content

Pull<O, R> sealed

sealedclassPull<O, R>

A Pull describes a process that can emit outputs of type O, evaluate effects of type IO, and eventually return a result of type R.

Available Extensions

Properties

hashCode no setter inherited

intgethashCode

The hash code for this object.

A hash code is a single integer which represents the state of the object that affects operator == comparisons.

All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).

If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.

Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.

Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.

If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.

Inherited from Object.

Implementation
dart
external int get hashCode;

runtimeType no setter inherited

TypegetruntimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
dart
external Type get runtimeType;

voided no setter

Pull<O,Unit>getvoided

Discards the result value, replacing it with Unit.

Implementation
dart
Pull<O, Unit> get voided => as(Unit());

Extension 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

append()

Pull<O2,R2>append<O2, R2>(Pull<O2,R2>Function()next)

Unsafe Cast Warning:

This method performs an unsafe cast (this as Pull<O2, R>) to allow type widening. If O is not a subtype of O2, this function will throw a TypeError at runtime.

Implementation
dart
Pull<O2, R2> append<O2, R2>(Function0<Pull<O2, R2>> next) => flatMap((_) => next());

as()

Pull<O,R2>as<R2>(R2s)

Replaces the result value with s.

Implementation
dart
Pull<O, R2> as<R2>(R2 s) => map((_) => s);

flatMap()

Pull<O2,R2>flatMap<O2, R2>(Pull<O2,R2>Function(R)f)

Runs this pull, then uses the result to determine the next pull.

f is a function that receives the result of this pull and returns the next step.

Unsafe Cast Warning:

This method performs an unsafe cast (this as Pull<O2, R>) to allow type widening. If O is not a subtype of O2, this function will throw a TypeError at runtime.

Implementation
dart
Pull<O2, R2> flatMap<O2, R2>(Function1<R, Pull<O2, R2>> f) => _Bind(this as Pull<O2, R>, Fn1(f));

handleErrorWith()

Pull<O2,R>handleErrorWith<O2>(Pull<O2,R>Function(Object)f)

Handles errors raised in this Pull.

Unsafe Cast Warning:

This method performs an unsafe cast (this as Pull<O2, R>) to allow type widening. If O is not a subtype of O2, this function will throw a TypeError at runtime.

Implementation
dart
Pull<O2, R> handleErrorWith<O2>(Function1<Object, Pull<O2, R>> f) =>
    _Handle(this as Pull<O2, R>, Fn1(f));

map()

Pull<O,R2>map<R2>(R2Function(R)f)

Maps the result type.

Implementation
dart
Pull<O, R2> map<R2>(Function1<R, R2> f) => flatMap((r) => Pull.pure(f(r)));

noSuchMethod() inherited

dynamicnoSuchMethod(Invocationinvocation)

Invoked when a nonexistent method or property is accessed.

A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).

Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.

A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:

dart
class MockList<T> implements List<T> {
  noSuchMethod(Invocation invocation) {
    log(invocation);
    super.noSuchMethod(invocation); // Will throw.
  }
}
void main() {
  MockList().add(42);
}

This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.

If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.

The default behavior is to throw a NoSuchMethodError.

Inherited from Object.

Implementation
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);

toString() inherited

StringtoString()

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Inherited from Object.

Implementation
dart
external String toString();

Extension 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);
      }
    });
  });
}

flatten() extension

Pull<O,R>flatten()

Sequences the inner pull after the outer, merging their outputs.

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

Implementation
dart
Pull<O, R> flatten() => flatMap(identity);

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)),
    );
  });
}

Operators

operator ==() inherited

booloperator ==(Objectother)

The equality operator.

The default behavior for all Objects is to return true if and only if this object and other are the same object.

Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:

  • Total: It must return a boolean for all arguments. It should never throw.

  • Reflexive: For all objects o, o == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must be true.

The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.

If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.

Inherited from Object.

Implementation
dart
external bool operator ==(Object other);

Static Properties

done final

finalPull<Never,Unit>done

A pull that emits no elements and terminates successfully. Alias for unit.

Implementation
dart
static final Pull<Never, Unit> done = unit;

getScope read / write

Pull<Never,Scope>getScope

getter:

A Pull that returns the current Scope without emitting any output.

setter:

A Pull that returns the current Scope without emitting any output.

Implementation
dart
static Pull<Never, Scope> getScope = const _GetScope();

outUnit final

finalPull<Unit,Unit>outUnit

A pre-allocated pull that emits a single Unit element.

Implementation
dart
static final Pull<Unit, Unit> outUnit = _Output(Chunk.unit);

unit read / write

Pull<Never,Unit>unit

getter:

A Pull that emits nothing and returns Unit.

setter:

A Pull that emits nothing and returns Unit.

Implementation
dart
static Pull<Never, Unit> unit = _Pure(Unit());

Static Methods

acquire()

Pull<Never,R>acquire<R>(IO<R>acquire,IO<Unit>Function(R,ExitCase)release,);

Acquires a resource that will be released with release when the enclosing Scope closes.

The acquisition itself is not cancelable. Use acquireCancelable if the acquisition should be interruptible.

Implementation
dart
static Pull<Never, R> acquire<R>(
  IO<R> acquire,
  Function2<R, ExitCase, IO<Unit>> release,
) => _Acquire(acquire, Fn2(release), cancelable: false);

acquireCancelable()

Pull<Never,R>acquireCancelable<R>(IO<R>Function(Poll)acquire,IO<Unit>Function(R,ExitCase)release,);

Like acquire but the acquisition IO is wrapped in IO.uncancelable so that a cancelation request is only honoured after the resource is fully acquired and its finalizer is registered.

Implementation
dart
static Pull<Never, R> acquireCancelable<R>(
  Function1<Poll, IO<R>> acquire,
  Function2<R, ExitCase, IO<Unit>> release,
) => _Acquire(IO.uncancelable(acquire), Fn2(release), cancelable: true);

eval()

Pull<Never,R>eval<R>(IO<R>io)

Lifts an IO into a Pull that evaluates it and returns the result.

Implementation
dart
static Pull<Never, R> eval<R>(IO<R> io) => _Eval(io);

fail()

Pull<Never,Never>fail(Objecterr, [StackTrace?stackTrace])

A Pull that immediately fails with err.

Implementation
dart
static Pull<Never, Never> fail(Object err, [StackTrace? stackTrace]) => _Fail(err, stackTrace);

interruptWhen()

Pull<O,R>interruptWhen<O, R>(Pull<O,R>pull,IO<Either<Object,Unit>>haltWhen,);

Wraps pull so that it is interrupted when haltWhen completes.

haltWhen is an IO<Either<Object, Unit>>:

The halt signal is checked at each output step, and the scope is closed with the correct ExitCase so that resource finalizers (e.g. from Rill.bracketCase) observe the proper exit condition.

Implementation
dart
static Pull<O, R> interruptWhen<O, R>(
  Pull<O, R> pull,
  IO<Either<Object, Unit>> haltWhen,
) => _InterruptWhen(pull, haltWhen);

mapOutputNoScope()

Pull<P,Unit>mapOutputNoScope<O, P>(Rill<O>s,PFunction(O)f,);

Maps the output of s via f without introducing a new Scope.

Implementation
dart
static Pull<P, Unit> mapOutputNoScope<O, P>(Rill<O> s, Function1<O, P> f) =>
    s.pull.echo.unconsFlatMap((hd) => Pull.output(hd.map(f)));

output()

Pull<O,Unit>output<O>(Chunk<O>chunk)

Emits chunk, or does nothing if chunk is empty.

Implementation
dart
static Pull<O, Unit> output<O>(Chunk<O> chunk) => chunk.isEmpty ? Pull.done : _Output(chunk);

output1()

Pull<O,Unit>output1<O>(Ovalue)

Emits a single element value.

Implementation
dart
static Pull<O, Unit> output1<O>(O value) => _Output(chunk([value]));

outputOption1()

Pull<O,Unit>outputOption1<O>(Option<O>opt)

Emits opt's value if it is Some, otherwise emits nothing.

Implementation
dart
static Pull<O, Unit> outputOption1<O>(Option<O> opt) =>
    opt.map(output1).getOrElse(() => Pull.done);

pure()

Pull<Never,R>pure<R>(Rr)

A Pull that emits nothing and returns r.

Implementation
dart
static Pull<Never, R> pure<R>(R r) => _Pure(r);

raiseError()

Pull<Never,Never>raiseError(Objecterr, [StackTrace?stackTrace])

Alias for fail.

Implementation
dart
static Pull<Never, Never> raiseError(Object err, [StackTrace? stackTrace]) =>
    _Fail(err, stackTrace);

scope()

Pull<O,Unit>scope<O>(Pull<O,Unit>pull)

Wraps pull in a fresh Scope, closing it (with the appropriate ExitCase) when pull completes, errors, or is canceled.

Implementation
dart
static Pull<O, Unit> scope<O>(Pull<O, Unit> pull) => _OpenScope<O>().flatMap((newScope) {
  return _RunInScope<O, Unit>(pull, newScope)
      .handleErrorWith<O>(
        (err) => _CloseScope<O>(
          newScope,
          ExitCase.errored(err),
        ).append<O, Unit>(() => Pull.raiseError(err)),
      )
      .flatMap((_) {
        return _CloseScope<O>(newScope, ExitCase.succeeded()).handleErrorWith<O>(
          (err) => _CloseScope<O>(
            newScope,
            ExitCase.errored(err),
          ).append<O, Unit>(() => Pull.raiseError(err)),
        );
      });
});

suspend()

Pull<O2,R2>suspend<O, R>(Pull<O,R>Function()f)

Defers construction of a Pull until it is stepped, preventing stack overflow for recursive definitions.

Implementation
dart
static Pull<O, R> suspend<O, R>(Function0<Pull<O, R>> f) => Pull.unit.flatMap((_) => f());