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.