source: node_modules/es-toolkit/dist/compat/array/findLast.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 3.7 KB
Line 
1import { ListIterateeCustom } from '../_internal/ListIterateeCustom.mjs';
2import { ListIteratorTypeGuard } from '../_internal/ListIteratorTypeGuard.mjs';
3import { ObjectIterateeCustom } from '../_internal/ObjectIteratee.mjs';
4import { ObjectIteratorTypeGuard } from '../_internal/ObjectIterator.mjs';
5
6/**
7 * Finds the last element in a collection that satisfies the predicate.
8 *
9 * @template T, S
10 * @param {ArrayLike<T> | null | undefined} collection - The collection to search.
11 * @param {ListIteratorTypeGuard<T, S>} predicate - The predicate function with type guard.
12 * @param {number} [fromIndex] - The index to start searching from.
13 * @returns {S | undefined} The last element that satisfies the predicate.
14 *
15 * @example
16 * const users = [{ user: 'barney', age: 36 }, { user: 'fred', age: 40 }, { user: 'pebbles', age: 18 }];
17 * findLast(users, (o): o is { user: string; age: number } => o.age < 40);
18 * // => { user: 'pebbles', age: 18 }
19 */
20declare function findLast<T, S extends T>(collection: ArrayLike<T> | null | undefined, predicate: ListIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined;
21/**
22 * Finds the last element in a collection that satisfies the predicate.
23 *
24 * @template T
25 * @param {ArrayLike<T> | null | undefined} collection - The collection to search.
26 * @param {ListIterateeCustom<T, boolean>} [predicate] - The predicate function, partial object, property-value pair, or property name.
27 * @param {number} [fromIndex] - The index to start searching from.
28 * @returns {T | undefined} The last element that satisfies the predicate.
29 *
30 * @example
31 * const users = [{ user: 'barney', age: 36 }, { user: 'fred', age: 40 }, { user: 'pebbles', age: 18 }];
32 * findLast(users, o => o.age < 40);
33 * // => { user: 'pebbles', age: 18 }
34 *
35 * findLast(users, { age: 36 });
36 * // => { user: 'barney', age: 36 }
37 *
38 * findLast(users, ['age', 18]);
39 * // => { user: 'pebbles', age: 18 }
40 *
41 * findLast(users, 'age');
42 * // => { user: 'fred', age: 40 }
43 */
44declare function findLast<T>(collection: ArrayLike<T> | null | undefined, predicate?: ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined;
45/**
46 * Finds the last element in an object that satisfies the predicate with type guard.
47 *
48 * @template T, S
49 * @param {T | null | undefined} collection - The object to search.
50 * @param {ObjectIteratorTypeGuard<T, S>} predicate - The predicate function with type guard.
51 * @param {number} [fromIndex] - The index to start searching from.
52 * @returns {S | undefined} The last element that satisfies the predicate.
53 *
54 * @example
55 * const obj = { a: 1, b: 'hello', c: 3 };
56 * findLast(obj, (value): value is string => typeof value === 'string');
57 * // => 'hello'
58 */
59declare function findLast<T extends object, S extends T[keyof T]>(collection: T | null | undefined, predicate: ObjectIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined;
60/**
61 * Finds the last element in an object that satisfies the predicate.
62 *
63 * @template T
64 * @param {T | null | undefined} collection - The object to search.
65 * @param {ObjectIterateeCustom<T, boolean>} [predicate] - The predicate function, partial object, property-value pair, or property name.
66 * @param {number} [fromIndex] - The index to start searching from.
67 * @returns {T[keyof T] | undefined} The last element that satisfies the predicate.
68 *
69 * @example
70 * const obj = { a: { id: 1, name: 'Alice' }, b: { id: 2 }, c: { id: 3, name: 'Bob' } };
71 * findLast(obj, o => o.id > 1);
72 * // => { id: 3, name: 'Bob' }
73 *
74 * findLast(obj, { name: 'Bob' });
75 * // => { id: 3, name: 'Bob' }
76 *
77 * findLast(obj, 'name');
78 * // => { id: 3, name: 'Bob' }
79 */
80declare function findLast<T extends object>(collection: T | null | undefined, predicate?: ObjectIterateeCustom<T, boolean>, fromIndex?: number): T[keyof T] | undefined;
81
82export { findLast };
Note: See TracBrowser for help on using the repository browser.