API · Transform

compact()

Remove JavaScript falsy values while preserving every other value unchanged.

Example

await exstream([0, 1, false, 2, '', null, 3]).compact().toArray()
// [1, 2, 3]

Behavior

compact() drops exactly false, 0, -0, 0n, '', null, undefined, and NaN, following normal JavaScript truthiness. Values such as empty arrays, empty objects, and the string '0' remain.

It is synchronous, stable, and one-to-zero-or-one: output order is unchanged, no queue is added, and downstream pressure propagates upstream. Record contexts pass through with retained values. Existing record errors pass through and do not participate in the truthiness test.

Errors

compact() has no callback and does not create operator errors. Unhandled record errors and fatal failures retain their normal pipeline behavior.

Forms

Available on streams and reusable pipelines:

stream.compact()
exstream.pipeline().compact()

Signature

compact(): Exstream<Exclude<T, false | 0 | '' | null | undefined>, C>

filter(), reject(), isDefined() on the utility API