| 1 | import { ListIterateeCustom } from '../_internal/ListIterateeCustom.mjs';
|
|---|
| 2 | import { ListIteratorTypeGuard } from '../_internal/ListIteratorTypeGuard.mjs';
|
|---|
| 3 | import { ObjectIterateeCustom } from '../_internal/ObjectIteratee.mjs';
|
|---|
| 4 | import { ObjectIteratorTypeGuard } from '../_internal/ObjectIterator.mjs';
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * Finds the first element in an array-like object that matches a type guard predicate.
|
|---|
| 8 | *
|
|---|
| 9 | * @param collection - The array-like object to search
|
|---|
| 10 | * @param predicate - The type guard function to test each element
|
|---|
| 11 | * @param fromIndex - The index to start searching from
|
|---|
| 12 | * @returns The first element that matches the type guard, or undefined if none found
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * find([1, '2', 3], (x): x is number => typeof x === 'number')
|
|---|
| 16 | * // => 1
|
|---|
| 17 | */
|
|---|
| 18 | declare function find<T, U extends T>(collection: ArrayLike<T> | null | undefined, predicate: ListIteratorTypeGuard<T, U>, fromIndex?: number): U | undefined;
|
|---|
| 19 | /**
|
|---|
| 20 | * Finds the first element in an array-like object that matches a predicate.
|
|---|
| 21 | *
|
|---|
| 22 | * @param collection - The array-like object to search
|
|---|
| 23 | * @param predicate - The function or shorthand to test each element
|
|---|
| 24 | * @param fromIndex - The index to start searching from
|
|---|
| 25 | * @returns The first matching element, or undefined if none found
|
|---|
| 26 | *
|
|---|
| 27 | * @example
|
|---|
| 28 | * find([1, 2, 3], x => x > 2)
|
|---|
| 29 | * // => 3
|
|---|
| 30 | *
|
|---|
| 31 | * find([{ a: 1 }, { a: 2 }], { a: 2 })
|
|---|
| 32 | * // => { a: 2 }
|
|---|
| 33 | */
|
|---|
| 34 | declare function find<T>(collection: ArrayLike<T> | null | undefined, predicate?: ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined;
|
|---|
| 35 | /**
|
|---|
| 36 | * Finds the first value in an object that matches a type guard predicate.
|
|---|
| 37 | *
|
|---|
| 38 | * @param collection - The object to search
|
|---|
| 39 | * @param predicate - The type guard function to test each value
|
|---|
| 40 | * @param fromIndex - The index to start searching from
|
|---|
| 41 | * @returns The first value that matches the type guard, or undefined if none found
|
|---|
| 42 | *
|
|---|
| 43 | * @example
|
|---|
| 44 | * find({ a: 1, b: '2', c: 3 }, (x): x is number => typeof x === 'number')
|
|---|
| 45 | * // => 1
|
|---|
| 46 | */
|
|---|
| 47 | declare function find<T extends object, U extends T[keyof T]>(collection: T | null | undefined, predicate: ObjectIteratorTypeGuard<T, U>, fromIndex?: number): U | undefined;
|
|---|
| 48 | /**
|
|---|
| 49 | * Finds the first value in an object that matches a predicate.
|
|---|
| 50 | *
|
|---|
| 51 | * @param collection - The object to search
|
|---|
| 52 | * @param predicate - The function or shorthand to test each value
|
|---|
| 53 | * @param fromIndex - The index to start searching from
|
|---|
| 54 | * @returns The first matching value, or undefined if none found
|
|---|
| 55 | *
|
|---|
| 56 | * @example
|
|---|
| 57 | * find({ a: 1, b: 2 }, x => x > 1)
|
|---|
| 58 | * // => 2
|
|---|
| 59 | *
|
|---|
| 60 | * find({ a: { x: 1 }, b: { x: 2 } }, { x: 2 })
|
|---|
| 61 | * // => { x: 2 }
|
|---|
| 62 | */
|
|---|
| 63 | declare function find<T extends object>(collection: T | null | undefined, predicate?: ObjectIterateeCustom<T, boolean>, fromIndex?: number): T[keyof T] | undefined;
|
|---|
| 64 |
|
|---|
| 65 | export { find };
|
|---|