arrayOf :: Function β†’ [ a ] β†’ Boolean
Takes a validator and returns a new function that makes sure the received array matches the defined validator for each one if its elements.
import arrayOf from 'deep-waters/arrayOf';
import isNumber from 'deep-waters/isNumber';
import isString from 'deep-waters/isString';
// array of numbers only
const arrayOfNumbers = arrayOf(isNumber);
arrayOfNumbers([1, 2, 3, 4]); // β†’ true;
arrayOfNumbers(['s', 't,' 'r', 'i', 'n', 'g']); // β†’ false;
// array of multiple types
const numAndStrings = arrayOf(or(isNumber, isString));
numAndStrings([1, 2, 3, 4, 'can I have a little more?']); // β†’ true;
arrayOf is actually a semantic shortcut to every​
Copy link