iterable-some
v1.0.1
Published
`Array.some` for iterables.
Downloads
4
Maintainers
Readme
::some()
Array.some
for iterables.
Installation
$ npm install iterable-some
Usage
import some from 'iterable-some/module';
// or:
const some = require('iterable-some');
These are all true
:
[true]::some(function() { return this; });
[false, null, 0, 'truthy']::some(function() { return this; });
new Set([5])
::some(function() { return this > 4; })
;
new Map([2, 'nope'], [5, 'yup'])
::some(function() { return this === 'yup'; })
;
– and these are false
:
[false, false]::some(function() { return this; });
[]::some(function() { return this; });
new Set([3, 1, 0, 4])
::some(function() { return this > 4; })
;
::some()
is lazy – just as Array.some
. It stops executing the condition
as soon as it finds one match:
[0, 1, 'not checked']::some(function() {
if (this > 0) return true;
if (this === 'not checked') throw 'No worries, this won’t be thrown.'
});
It works great with trine-style libraries:
import isTruthy from 'this-is-truthy/module';
[null, undefined, 0, NaN]::some(isTruthy);
//» false
Huh?
If you’re wondering what the ::
thing means, you’d better read this excellent overview by @jussi-kalliokoski or have a look at the function bind syntax proposal.