Repository URL to install this package:
|
Version:
6.0.4 ▾
|
import { Predicate } from '../_typings'
import curry from '../fp/curry'
/**
* map all values in an array to see if all match
* Returns `true` if all elements of the list match the predicate, `false` if there are any that don't.
*
* @alias every
* @name all
* @memberOf conditional
* @since 4.0.1
*
* @TODO `not(some)` ?
*
* @curried
* @param {Function} predicate match the value
* @param {Array} list to match against predicate
* @return {boolean} all match predicate
*
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every mozilla-every}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L262 underscore-all}
* {@link https://github.com/ramda/ramda/blob/master/src/all.js ramda-all}
* @see {@link ramda-all}
* @see {@link underscore-all}
* @see {@link mozilla-every}
* @see fp/curry
*
* @sig (a -> Boolean) -> [a] -> Boolean
*
* @example
*
* const allBoolean = all(x => typeof x === 'boolean'q)
*
* allBoolean([true])
* //=> true
*
* allBoolean([1])
* //=> false
*
*/
const _all = <Type = any>(predicate: Predicate<Type>, list: Type[]): boolean => {
for (let i in list) {
if (!predicate(list[i])) return false
}
return true
}
const all = curry(2, _all)
export default all