| 1 | /**
|
|---|
| 2 | * Finds the first value in a Map for which the predicate function returns true.
|
|---|
| 3 | *
|
|---|
| 4 | * This function iterates through the entries of the Map and returns the value of the first
|
|---|
| 5 | * entry for which the predicate function returns true. If no entry satisfies the predicate,
|
|---|
| 6 | * it returns undefined.
|
|---|
| 7 | *
|
|---|
| 8 | * @template K - The type of keys in the Map.
|
|---|
| 9 | * @template V - The type of values in the Map.
|
|---|
| 10 | * @param {Map<K, V>} map - The Map to search.
|
|---|
| 11 | * @param {(value: V, key: K, map: Map<K, V>) => boolean} doesMatch - A predicate function that tests each entry.
|
|---|
| 12 | * @returns {V | undefined} The value of the first entry that satisfies the predicate, or undefined if none found.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * const map = new Map([
|
|---|
| 16 | * ['apple', { color: 'red', quantity: 10 }],
|
|---|
| 17 | * ['banana', { color: 'yellow', quantity: 5 }],
|
|---|
| 18 | * ['grape', { color: 'purple', quantity: 15 }]
|
|---|
| 19 | * ]);
|
|---|
| 20 | * const result = findValue(map, (value) => value.quantity > 10);
|
|---|
| 21 | * // result will be: { color: 'purple', quantity: 15 }
|
|---|
| 22 | */
|
|---|
| 23 | declare function findValue<K, V>(map: Map<K, V>, doesMatch: (value: V, key: K, map: Map<K, V>) => boolean): V | undefined;
|
|---|
| 24 |
|
|---|
| 25 | export { findValue };
|
|---|