Skip to content

fx() function

fx は既存の fxts が提供する関数をメソッドチェーンで使用できるようにします。すべての関数がメソッドとして提供されているわけではなく、必要に応じて chain を通じて接続できます。

see guide

Signature:

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

Example

ts
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

Released under the Apache-2.0 License.