/** * Iterable helpers * * Provides exported iterable helper functions: * - getIterableElements: expand any iterable to a flat list * - expandIterator: drive an iterator protocol to completion * - expandStream: drain an async stream to a list * * Module functions shared across the evaluator. * The evaluate* operator methods (each/map/fold/filter) are removed. * * @internal */ import type { SourceLocation } from '../../../../types.js'; import type { RillValue } from '../../types/structures.js'; import type { RuntimeContext } from '../../types/runtime.js'; import type { TypeHaltSite } from '../../types/halt.js'; /** * Get elements from an iterable value (list, string, dict, iterator, or stream). * * Raises RILL-R003 for vector input. * Raises RILL-R002 for non-iterable input. * * @param input - The value to iterate over * @param ctx - Runtime context (used by iterator/stream expansion) * @param node - AST node providing span for error locations * @param limit - Maximum iteration count (default: DEFAULT_MAX_ITERATIONS) */ export declare function getIterableElements(input: RillValue, ctx: RuntimeContext, node: { span: { start: SourceLocation; }; }, limit?: number): Promise; /** * Validate a single stream chunk value before it is accepted into the * expanded element list. * * Halts as a catchable `INVALID_INPUT` for: * - non-finite numbers (NaN, Infinity, -Infinity) * - `null` * - callable/function values * - `undefined` (previously dropped silently, which under-counted the * expanded stream by one element per occurrence) * * @param value - The chunk value to validate * @param index - 0-based chunk index, used in the halt message * @param site - Halt site describing the calling stream operator */ export declare function validateStreamChunk(value: RillValue | undefined, index: number, site: TypeHaltSite): void; /** * Result of a lazy stream/iterator walk: the per-element results produced * by `onElement`, and whether the walk stopped because the body raised * `break` (`broke: true`) versus draining the source to completion. */ export interface LazyWalkResult { results: RillValue[]; broke: boolean; } /** * Drive a stream or iterator one raw step at a time, invoking `onElement` * for each produced value instead of materializing the whole sequence up * front via `getIterableElements`. Used by `seq`/`acc` so a `break` in the * body bounds how many steps are pulled from an infinite stream/iterator. * * Preserves, per input kind, the same guarantees the eager * expandStream/expandIterator paths gave: * - stream input: per-chunk `validateStreamChunk` and cross-chunk type * consistency (`#TYPE_MISMATCH`), matching expandStream. * - iterator input: no chunk validation or type-consistency check, * matching expandIterator (which does neither). * - both: `checkAborted` per step and a raw-step `limit` ceiling that halts * fatally with `#RILL_R010` when exceeded (ADR-0054), matching * expandStream/expandIterator's fatal classification. * * On `BreakSignal` from `onElement`, disposes the stream (a no-op for * iterators, which carry no dispose hook) and returns the partial results * collected so far (`broke: true`). On any other throw — a body halt or a * stream/iterator protocol error — disposes and re-throws. * * @param input - The stream or iterator value being walked * @param ctx - Runtime context (used for abort checks and callable invocation) * @param node - AST node providing span for error locations * @param fnName - Calling builtin's name, used in halt-site diagnostics * @param onElement - Invoked with each produced value and its 0-based index * @param limit - Maximum raw-step count (default: DEFAULT_MAX_ITERATIONS) */ export declare function walkStreamOrIteratorElements(input: RillValue, ctx: RuntimeContext, node: { span: { start: SourceLocation; }; }, fnName: string, onElement: (element: RillValue, index: number) => Promise, limit?: number): Promise;