Pull<O, R> sealed
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
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
external int get hashCode;runtimeType no setter inherited
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;voided no setter
Discards the result value, replacing it with Unit.
Implementation
Pull<O, Unit> get voided => as(Unit());Extension Properties
rill extension no setter
Converts this Pull into a Rill wrapped in its own Scope.
Available on Pull<O, R>, provided by the PullOps<O> extension
Implementation
Rill<O> get rill => Rill._scoped(this);rillNoScope extension no setter
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
Rill<O> get rillNoScope => Rill._noScope(this);uncons extension no setter
Peels off the next chunk of the current pull.
Returns a Pull that emits nothing, but evaluates to an Option containing:
- The next chunk IList<O>
- The remainder of the pull Pull<O, Unit>
Available on Pull<O, R>, provided by the PullOps<O> extension
Implementation
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()
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
Pull<O2, R2> append<O2, R2>(Function0<Pull<O2, R2>> next) => flatMap((_) => next());as()
Replaces the result value with s.
Implementation
Pull<O, R2> as<R2>(R2 s) => map((_) => s);flatMap()
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
Pull<O2, R2> flatMap<O2, R2>(Function1<R, Pull<O2, R2>> f) => _Bind(this as Pull<O2, R>, Fn1(f));handleErrorWith()
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
Pull<O2, R> handleErrorWith<O2>(Function1<Object, Pull<O2, R>> f) =>
_Handle(this as Pull<O2, R>, Fn1(f));map()
Maps the result type.
Implementation
Pull<O, R2> map<R2>(Function1<R, R2> f) => flatMap((r) => Pull.pure(f(r)));noSuchMethod() inherited
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:
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis 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:
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
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);toString() inherited
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
external String toString();Extension Methods
flatMapOutput() extension
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
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
Sequences the inner pull after the outer, merging their outputs.
Available on Pull<O, R>, provided by the PullFlattenOps<O, R> extension
Implementation
Pull<O, R> flatten() => flatMap(identity);unconsFlatMap() extension
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
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
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 == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must 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
external bool operator ==(Object other);Static Properties
done final
A pull that emits no elements and terminates successfully. Alias for unit.
Implementation
static final Pull<Never, Unit> done = unit;getScope read / write
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
static Pull<Never, Scope> getScope = const _GetScope();outUnit final
A pre-allocated pull that emits a single Unit element.
Implementation
static final Pull<Unit, Unit> outUnit = _Output(Chunk.unit);unit read / write
getter:
A Pull that emits nothing and returns Unit.
setter:
A Pull that emits nothing and returns Unit.
Implementation
static Pull<Never, Unit> unit = _Pure(Unit());Static Methods
acquire()
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
static Pull<Never, R> acquire<R>(
IO<R> acquire,
Function2<R, ExitCase, IO<Unit>> release,
) => _Acquire(acquire, Fn2(release), cancelable: false);acquireCancelable()
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
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()
Lifts an IO into a Pull that evaluates it and returns the result.
Implementation
static Pull<Never, R> eval<R>(IO<R> io) => _Eval(io);fail()
A Pull that immediately fails with err.
Implementation
static Pull<Never, Never> fail(Object err, [StackTrace? stackTrace]) => _Fail(err, stackTrace);interruptWhen()
Wraps pull so that it is interrupted when haltWhen completes.
haltWhen is an IO<Either<Object, Unit>>:
Right(Unit())→ clean interruption (scope closed with ExitCase.canceled)Left(err)→ interruption with error (scope closed with ExitCase.errored)
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
static Pull<O, R> interruptWhen<O, R>(
Pull<O, R> pull,
IO<Either<Object, Unit>> haltWhen,
) => _InterruptWhen(pull, haltWhen);mapOutputNoScope()
Maps the output of s via f without introducing a new Scope.
Implementation
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()
Emits chunk, or does nothing if chunk is empty.
Implementation
static Pull<O, Unit> output<O>(Chunk<O> chunk) => chunk.isEmpty ? Pull.done : _Output(chunk);output1()
Emits a single element value.
Implementation
static Pull<O, Unit> output1<O>(O value) => _Output(chunk([value]));outputOption1()
Emits opt's value if it is Some, otherwise emits nothing.
Implementation
static Pull<O, Unit> outputOption1<O>(Option<O> opt) =>
opt.map(output1).getOrElse(() => Pull.done);pure()
A Pull that emits nothing and returns r.
Implementation
static Pull<Never, R> pure<R>(R r) => _Pure(r);raiseError()
Alias for fail.
Implementation
static Pull<Never, Never> raiseError(Object err, [StackTrace? stackTrace]) =>
_Fail(err, stackTrace);scope()
Wraps pull in a fresh Scope, closing it (with the appropriate ExitCase) when pull completes, errors, or is canceled.
Implementation
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()
Defers construction of a Pull until it is stepped, preventing stack overflow for recursive definitions.
Implementation
static Pull<O, R> suspend<O, R>(Function0<Pull<O, R>> f) => Pull.unit.flatMap((_) => f());