Skip to content

parseAsyncIterable

Attempts to parse a value into an async iterable. This parser is strict: the value must already implement a callable [Symbol.asyncIterator] method. No coercion is performed. It mirrors the behavior of validateAsyncIterable but returns a structured ParseResult.

It never throws and never mutates input.

Signature

function parseAsyncIterable<T = unknown>(value: unknown): ParseResult<AsyncIterable<T>>

Parameters

Returns

Always includes:

  • ok: true, value: AsyncIterable<T>, issues: []: When the value is async iterable.
  • ok: false, value: null, issues: string[]: When the value is not async iterable.

Behavior

  • Uses isAsyncIterable internally.
  • Accepts:
  • Async generators.
  • Objects with a callable Symbol.asyncIterator.
  • Custom async iterable implementations.
  • Rejects:
  • Sync iterables (arrays, strings, sets, maps),
  • null and undefined.
  • Numbers and booleans.
  • Plain objects without an async iterator.
  • Objects with non-callable async iterator properties.
  • Never throws and never mutates input.

Examples

async function* gen() {
    yield 1;
    yield 2;
}

parseAsyncIterable(gen())
// { ok: true, value: AsyncGenerator, issues: [] }

parseAsyncIterable([1, 2, 3])
// { ok: false, value: null, issues: ["Value must be an async iterable"] }

parseAsyncIterable(null)
// { ok: false, value: null, issues: ["Value must be an async iterable"] }

Notes

  • This parser is intentionally strict and does not attempt to normalize or coerce values into async iterables.
  • For coercive behavior, use normalizeAsyncIterable instead.
  • Suitable for strict protocol checks before async iteration logic.