Pull<O, R> sealed
sealed class Pull<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
int get hashCodeThe 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
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;voided no setter
Implementation
Pull<O, Unit> get voided => as(Unit());Extension Properties
rill extension no setter
Rill<O> get rillAvailable on Pull<O, R>, provided by the PullOps<O> extension
Implementation
Rill<O> get rill => Rill._scoped(this);rillNoScope extension no setter
Rill<O> get rillNoScopeAvailable 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()
Pull<O, R2> as<R2>(R2 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()
Pull<O, R2> map<R2>(R2 Function(R) f)Maps the result type.
Implementation
Pull<O, R2> map<R2>(Function1<R, R2> f) => flatMap((r) => Pull.pure(f(r)));noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)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
String toString()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
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
Pull<O, R> flatten()Available on Pull<O, R>, provided by the PullFlattenOps<O, R> extension
Implementation
Pull<O, R> flatten() => flatMap(identity);unconsFlatMap() extension
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
bool operator ==(Object other)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
Implementation
static final Pull<Never, Unit> done = unit;getScope read / write
Implementation
static Pull<Never, Scope> getScope = const _GetScope();outUnit final
Implementation
static final Pull<Unit, Unit> outUnit = _Output(Chunk.unit);unit read / write
Implementation
static Pull<Never, Unit> unit = _Pure(Unit());Static Methods
acquire()
Implementation
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,
)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()
Implementation
static Pull<Never, R> eval<R>(IO<R> io) => _Eval(io);fail()
Pull<Never, Never> fail(Object err, [StackTrace? stackTrace])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()
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()
Implementation
static Pull<O, Unit> output<O>(Chunk<O> chunk) => chunk.isEmpty ? Pull.done : _Output(chunk);output1()
Implementation
static Pull<O, Unit> output1<O>(O value) => _Output(chunk([value]));outputOption1()
Implementation
static Pull<O, Unit> outputOption1<O>(Option<O> opt) =>
opt.map(output1).getOrElse(() => Pull.done);pure()
Pull<Never, R> pure<R>(R r)Implementation
static Pull<Never, R> pure<R>(R r) => _Pure(r);raiseError()
Pull<Never, Never> raiseError(Object err, [StackTrace? stackTrace])Implementation
static Pull<Never, Never> raiseError(Object err, [StackTrace? stackTrace]) =>
_Fail(err, stackTrace);scope()
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()
Implementation
static Pull<O, R> suspend<O, R>(Function0<Pull<O, R>> f) => Pull.unit.flatMap((_) => f());