Skip to main content

Function: all()

all(iterable, callbackFn)

all<ElementType, FilteredType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => element is FilteredType): iterable is IterableIterator<FilteredType>

Tests whether all elements in the iterable pass the test implemented by the provided function.

Type Parameters

Type Parameter
ElementType
FilteredType

Parameters

ParameterTypeDescription
iterableIterableResolvable<ElementType>The iterator to check.
callbackFn(element: ElementType, index: number) => element is FilteredTypeA 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.

Defined in

projects/utilities/packages/iterator-utilities/src/lib/every.ts:28

all(iterable, callbackFn)

all<ElementType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => boolean): boolean

Type Parameters

Type Parameter
ElementType

Parameters

ParameterType
iterableIterableResolvable<ElementType>
callbackFn(element: ElementType, index: number) => boolean

Returns

boolean

Defined in

projects/utilities/packages/iterator-utilities/src/lib/every.ts:32