Skip to main content

fx

fx() function

fx allows functions provided by existing fxts to be used in a method chaining. Not all functions are provided as methods and can be connected through chain if necessary.

see guide

Signature:
declare function fx<T extends Iterable<unknown> | AsyncIterable<unknown>>(a: T): T extends Iterable<unknown> ? FxIterable<IterableInfer<T>> : FxAsyncIterable<IterableInfer<T>>;

Example

const syncArr1 = fx([1, 2, 3, 4])
.map((a) => a + 10)
.toArray(); // [11, 12, 13, 14]

// If you want to use another function that is not provided for the method, use `chain`.
const syncArr2 = fx([1, 2, 3, 4])
.chain(append(5))
.map((a) => a + 10)
.toArray(); // [11, 12, 13, 14, 15]

const asyncArr1 = await fx([1, 2, 3, 4])
.toAsync()
.map((a) => a + 10)
.toArray(); // [11, 12, 13, 14]

const asyncArr2 = await fx(toAsync([1, 2, 3, 4]))
.map((a) => a + 10)
.toArray(); // [11, 12, 13, 14]

Open Source Code