Function firstEntryByPredicate

Finds first entry by iterable value. Expects a map with an iterable as values.

const map = new Map();
map.set('hello', 'a');
map.set('there', 'b');

const entry = firstEntryByPredicate(map, (value, key) => {
return (value === 'b');
});
// Entry is: ['there', 'b']

An alternative is firstEntryByValue to search by value.

  • Type Parameters

    • K
    • V

    Parameters

    • map: IWithEntries<K, V>

      Map to search

    • predicate: ((value: V, key: K) => boolean)

      Filter function returns true when there is a match of value

        • (value, key): boolean
        • Parameters

          • value: V
          • key: K

          Returns boolean

    Returns undefined | readonly [K, V]

    Entry, or undefined if filter function never returns true