Function: some()
some<
ElementType>(iterable:IterableResolvable<ElementType>,callbackFn: (element:ElementType,index:number) =>boolean):boolean
Defined in: projects/utilities/packages/iterator-utilities/src/lib/some.ts:33
Advances the iterable until it finds a matching element, returning true if it's found and false otherwise.
Type Parameters
| Type Parameter | 
|---|
| ElementType | 
Parameters
| Parameter | Type | Description | 
|---|---|---|
| iterable | IterableResolvable<ElementType> | An iterator to search for a value in. | 
| callbackFn | ( element:ElementType,index:number) =>boolean | A function to execute for each element produced by the iterator. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise. | 
Returns
boolean
true if the callback function returns a truthy value for at least one element. Otherwise, false.
Examples
import { some } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log(some(iterable, (value) => value % 2 === 0));
// Output: true
const iterable = [1, 2, 3, 4, 5];
console.log(some(iterable, (value) => value % 6 === 0));
// Output: false
Remarks
This function consumes the iterator until the value is found or the iterator is exhausted.