Skip to content

anyfn

Summary

True if one predicate returned logical true when applied to arguments.

Description

Takes one or more predicates and returns a function that takes any number of arguments and returns true if one predicate returned logical true when applied to these arguments. Returns false if none did.

Examples

Make sure that both x and y are either numbers or strings.

1
2
3
4
5
6
7
8
9
const is_num = x => typeof x == 'number';
const is_str = x => typeof x == 'string';

const num_or_str = anyfn( (x, y) => is_num(x) && is_num(y)
                        , (x, y) => is_str(x) && is_str(y));

num_or_str(  40,    2); //=> true
num_or_str('21', '21'); //=> true
num_or_str('40',    2); //=> false

Parameters

Name Type Description
fn function One or more predicates

Return

function