Repository URL to install this package:
|
Version:
6.0.4 ▾
|
import { Predicate } from '../_typings'
import curry from '../fp/curry'
/**
* @desc map all values in an array to see if **some** match, curried
* @memberOf conditional
* @since 4.0.1
*
* @param {Function} predicate match the value
* @param {Array | any} list values to match on the predicate
* @return {boolean} **some** match predicate
*
* @name some
* @alias any
* @func
*
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some mozilla-some}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L273 underscore-some}
* @see {@link underscore-some}
* @see {@link mozilla-some}
*
* @example
*
* const someBoolean = some(x => typeof x === 'boolean'q)
*
* someBoolean([true])
* //=> true
*
* someBoolean([1])
* //=> false
*
* someBoolean([1, true])
* //=> true
*
*/
function _some<Item = any>(test: Predicate<Item>, list: Item[]): boolean {
for (let i in list) {
if (test(list[i])) return true
}
return false
}
const some = curry(2, _some)
export default some