Function: every()
Call Signature
every<
ElementType,FilteredType>(iterable:IterableResolvable<ElementType>,callbackFn: (element:ElementType,index:number) =>element is FilteredType):iterable is IterableIterator<FilteredType>
Defined in: projects/utilities/packages/iterator-utilities/src/lib/every.ts:28
Tests whether all elements in the iterable pass the test implemented by the provided function.
Type Parameters
| Type Parameter |
|---|
ElementType |
FilteredType |
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | IterableResolvable<ElementType> | The iterator to check. |
callbackFn | (element: ElementType, index: number) => element is FilteredType | 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
iterable is IterableIterator<FilteredType>
true if callbackFn returns a truthy value for every element. Otherwise, false.
Example
import { every } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log(every(iterable, (value) => value < 10));
// Output: true
console.log(every(iterable, (value) => value < 3));
// Output: false
Remarks
This function consumes the entire iterator.
Call Signature
every<
ElementType>(iterable:IterableResolvable<ElementType>,callbackFn: (element:ElementType,index:number) =>boolean):boolean
Defined in: projects/utilities/packages/iterator-utilities/src/lib/every.ts:32
Tests whether all elements in the iterable pass the test implemented by the provided function.
Type Parameters
| Type Parameter |
|---|
ElementType |
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | IterableResolvable<ElementType> | The iterator to check. |
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 callbackFn returns a truthy value for every element. Otherwise, false.
Example
import { every } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log(every(iterable, (value) => value < 10));
// Output: true
console.log(every(iterable, (value) => value < 3));
// Output: false
Remarks
This function consumes the entire iterator.