nustack
ReferenceNulang

helpers.evaluation

Drive entries: run a compiled Program through the Runtime.

Module nu.lang.helpers.evaluation.

Drive entries: run a compiled Program through the Runtime.

Two families, by what the root yields:

  • value root: eval, aeval, eval_in_loop: return (value, ctx).
  • stream root: first, collect, afirst, alast, acollect: iterate the root and return either a single item or a list, with the Context after execution.

Each opens a fresh Budget sized by max_parallel and closes it on exit. Sync entries refuse a Program with an async-only subtree; callers must use the async sibling, or eval_in_loop as the deliberate bridge. Stream entries wrap iteration in safely_(a)closing so a short-circuit (first, partial collect) still finalizes the underlying generator.

NameCallMeaning
acollectlang.acollect(program, ctx=None, max_parallel=1)Async sibling of collect.
aevallang.aeval(program, ctx=None, max_parallel=1)Drive a Program asynchronously; return (value, ctx).
afirstlang.afirst(program, ctx=None, max_parallel=1)Async sibling of first.
alastlang.alast(program, ctx=None, max_parallel=1)Drain a stream-rooted Program and return the last item; (value, ctx).
collectlang.collect(program, ctx=None, max_parallel=1)Materialize a stream-rooted Program to a list; (values, ctx).
evallang.eval(program, ctx=None, max_parallel=1)Drive a Program synchronously; return (value, ctx).
eval_in_looplang.eval_in_loop(program, ctx=None, max_parallel=1)Drive an async-only Program from sync code by spinning a loop.
firstlang.first(program, ctx=None, max_parallel=1)Return the first item of a stream-rooted Program; (value, ctx).

acollect

Async sibling of collect.

lang.acollect(program, ctx=None, max_parallel=1)

Path nu.lang.acollect. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[list, Context].

Arguments

NameTypeDefaultMeaning
programProgram
ctxContext | NoneNone
max_parallelint1

Undocumented: example.

aeval

Drive a Program asynchronously; return (value, ctx).

lang.aeval(program, ctx=None, max_parallel=1)

Path nu.lang.aeval. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[object, Context].

Arguments

NameTypeDefaultMeaning
programProgram
ctxContext | NoneNone
max_parallelint1

Undocumented: example.

afirst

Async sibling of first.

lang.afirst(program, ctx=None, max_parallel=1)

Path nu.lang.afirst. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[object, Context].

Arguments

NameTypeDefaultMeaning
programProgram
ctxContext | NoneNone
max_parallelint1

Undocumented: example.

alast

Drain a stream-rooted Program and return the last item; (value, ctx).

lang.alast(program, ctx=None, max_parallel=1)

Path nu.lang.alast. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[object, Context].

Raises RuntimeError if the stream is empty.

Arguments

NameTypeDefaultMeaning
programProgram
ctxContext | NoneNone
max_parallelint1

Undocumented: example.

collect

Materialize a stream-rooted Program to a list; (values, ctx).

lang.collect(program, ctx=None, max_parallel=1)

Path nu.lang.collect. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[list, Context].

Arguments

NameTypeDefaultMeaning
programProgram
ctxContext | NoneNone
max_parallelint1

Undocumented: example.

eval

Drive a Program synchronously; return (value, ctx).

lang.eval(program, ctx=None, max_parallel=1)

Path nu.lang.eval. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[object, Context].

Arguments

NameTypeDefaultMeaning
programPrograma compiled Program.
ctxContext | NoneNonethe Context to drive against; a fresh one if omitted.
max_parallelint1tree-wide concurrency gate. 1 is sequential.

Undocumented: example.

eval_in_loop

Drive an async-only Program from sync code by spinning a loop.

lang.eval_in_loop(program, ctx=None, max_parallel=1)

Path nu.lang.eval_in_loop. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[object, Context].

Convenience for the rare top-level sync caller whose Program contains an async-only atom. Most callers should use aeval directly.

Arguments

NameTypeDefaultMeaning
programProgram
ctxContext | NoneNone
max_parallelint1

Undocumented: example.

first

Return the first item of a stream-rooted Program; (value, ctx).

lang.first(program, ctx=None, max_parallel=1)

Path nu.lang.first. Defined on nu.lang.helpers.evaluation, bound as a function. Builds tuple[object, Context].

Raises RuntimeError if the stream is empty.

Arguments

NameTypeDefaultMeaning
programProgram
ctxContext | NoneNone
max_parallelint1

Undocumented: example.

On this page