Skip to content

every

Checks if every entry of a Map satisfies the predicate. Short-circuits on the first mismatch.

Available since v3.0.3

import { every } from '@helpers4/map';
// or, from the all-in-one package (same code, one install):
import { every } from 'helpers4/map';
every<K, V>(map: ReadonlyMap<K, V>, predicate: function): boolean
ParameterTypeDescription
mapReadonlyMap<K, V>The Map to check
predicatefunctionFunction invoked with (value, key)

boolean — true if all entries match (vacuously true for an empty map), false otherwise

Returns false as soon as one entry fails the predicate.

every(new Map([['a', 1], ['b', 2]]), value => value > 0)
// => true

Vacuously true for an empty map.

every(new Map(), () => false)
// => true

View source on GitHub