Skip to content

juxt

Summary

Applies a series of functions to a series of values.

Description

Take one or more functions then take one or more values. Return an array with the results of applying each function to the values.

Examples

Producing a restaurant bill:

1
2
3
4
5
6
7
8
9
const items = (...xs) => xs.map(([i]) => i).join(', ');
const total = (...xs) => xs.reduce((t, [, p]) => t + p, 0);
const bill = juxt(items, total);

bill( ['burrito', 5.50]
    , ['beer'   , 4.50]
    , ['coffee' , 2.80]);

//=> ["burrito, beer, coffee", 12.8]

Parameters

Name Type Description
fn function

Return

function