when

when :: (Function, Function) → Function → Boolean

Takes two validators, the conditioncondition validator and the fnfn validator, then returns a new function receiving a value vv (of any type) and execute the fnfn validator only when the condition(v)condition(v) returns true.

It is largely used within the library itself to evaluate certain conditions:

contains.js
/* Part of the contains validator */


const contains = (value) => compose(
  when(isString, (string) => string.includes(value)),
  when(Array.isArray, arrayContains(value)),
  when(not(or(isString, Array.isArray)), stubFalse),
);
composeornot

Last updated