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.