@lou.codes/iterables
Version:
🔁 Iterable and AsyncIterable utils
19 lines (18 loc) • 631 B
TypeScript
import type { Maybe, ReadOnlyIterable, Unary } from "@lou.codes/types";
/**
* Returns the value of the first item in the iterable where predicate is
* `true`, `undefined` otherwise.
*
* @category Reducers
* @example
* ```typescript
* const findEven = find((number: number) => number % 2 === 0);
* findEven([1, 2, 3, 4]); // 2
* findEven([1, 3, 5, 7]); // undefined
* ```
* @param predicate Predicate function to search for item.
* @returns Curried function with `predicate` set in context.
*/
export declare const find: <Item>(
predicate: Unary<Item, boolean>,
) => (iterable: ReadOnlyIterable<Item>) => Maybe<Item>;