Skip to content

some

Summary

Apply functions to arguments until one returns logical true.

Description

Takes one or more functions and returns another function that takes any number of parameters.

Starting with the leftmost function applies each to the parameters until one returns logical true in which case all other functions are ignored and we return that value.

Otherwise returns whatever the last function has returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
const grade = some( when(gte(1)   , constant('Perfect'))
                  , when(gte(0.85), constant('Good'))
                  , when(gte(0.60), constant('Medium'))
                  , when(gte(0.34), constant('Poor'))
                  ,                 constant('No'));

grade(1);    //=> 'Perfect'
grade(0.92); //=> 'Good'
grade(0.70); //=> 'Medium'
grade(0.50); //=> 'Poor'
grade(0.20); //=> 'No'

Parameters

Name Type Description
fns function

Return

function