Skip to main content

juxt

juxt() function

juxt applies a list of functions to a list of values.

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

Example

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