Skip to content

some

Checks if at least one entry of a Map satisfies the predicate. Short-circuits on the first match.

Available since v3.0.3

import { some } from '@helpers4/map';
// or, from the all-in-one package (same code, one install):
import { some } from 'helpers4/map';
some<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 at least one entry matches, false otherwise (including for an empty map)

Returns true as soon as one entry satisfies the predicate.

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

Always returns false for an empty map.

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

View source on GitHub