API · Consume

value()

Consume a stream expected to contain zero or one successful value.

Signature

value(): T | undefined | Promise<T | undefined>

Example

const user = await exstream(users).findWhere({ id }).value()

Return mode

value() delegates to values(). A fully synchronous pipeline returns immediately; an asynchronous pipeline returns a promise. Zero values produce undefined, one produces that value, and more than one throws or rejects with an instruction to use values().

The method consumes the complete stream to prove there is no second value; it does not stop after the first. It therefore inherits collection memory, startup, and error behavior from values()/toPromise(). Use head().value() when only the first value matters.

Forms

value() is an instance-only convenience method:

const sync = exstream([42]).value()
const async = await exstream(fetchRows()).value()

values(), valuesSync(), head(), toPromise()