Skip to content

juxt() function

juxtは関数のリストを値のリストに適用します。

Signature:

typescript
declare function juxt<FS extends Array<Arrow>>(
  fs: readonly [...FS],
): (...args: JuxtArgs<FS>) => JuxtReturnTypes<FS>;

Example

ts
const range = juxt([Math.min, Math.max])(1, 2, 3, 4); // [1, 4]

// with pipe
const entries = (obj: { a: number; b: number }) =>
  pipe(
    [Object.keys, Object.values] as const,
    juxt,
    (f) => f(obj),
    apply(zip),
    toArray,
  );

entries({ a: 1, b: 2 }); // [ ["a", 1], ["b", 2] ]

see pipe, apply

Open Source Code

Released under the Apache-2.0 License.