source: node_modules/es-toolkit/dist/compat/array/flatMap.d.mts@ a762898

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

Added visualizations

  • Property mode set to 100644
File size: 3.6 KB
Line 
1import { ListIterator } from '../_internal/ListIterator.mjs';
2import { Many } from '../_internal/Many.mjs';
3import { ObjectIterator } from '../_internal/ObjectIterator.mjs';
4
5/**
6 * Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
7 *
8 * @template T
9 * @param {Record<string, Many<T>> | Record<number, Many<T>> | null | undefined} collection - The collection to iterate over.
10 * @returns {T[]} Returns the new flattened array.
11 *
12 * @example
13 * const obj = { a: [1, 2], b: [3, 4] };
14 * flatMap(obj);
15 * // => [1, 2, 3, 4]
16 */
17declare function flatMap<T>(collection: Record<string, Many<T>> | Record<number, Many<T>> | null | undefined): T[];
18/**
19 * Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
20 *
21 * @param {object | null | undefined} collection - The collection to iterate over.
22 * @returns {any[]} Returns the new flattened array.
23 *
24 * @example
25 * flatMap({ a: 1, b: 2 });
26 * // => [1, 2]
27 */
28declare function flatMap(collection: object | null | undefined): any[];
29/**
30 * Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
31 *
32 * @template T, R
33 * @param {ArrayLike<T> | null | undefined} collection - The collection to iterate over.
34 * @param {ListIterator<T, Many<R>>} iteratee - The function invoked per iteration.
35 * @returns {R[]} Returns the new flattened array.
36 *
37 * @example
38 * function duplicate(n) {
39 * return [n, n];
40 * }
41 *
42 * flatMap([1, 2], duplicate);
43 * // => [1, 1, 2, 2]
44 */
45declare function flatMap<T, R>(collection: ArrayLike<T> | null | undefined, iteratee: ListIterator<T, Many<R>>): R[];
46/**
47 * Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
48 *
49 * @template T, R
50 * @param {T | null | undefined} collection - The object to iterate over.
51 * @param {ObjectIterator<T, Many<R>>} iteratee - The function invoked per iteration.
52 * @returns {R[]} Returns the new flattened array.
53 *
54 * @example
55 * const obj = { a: 1, b: 2 };
56 * flatMap(obj, (value, key) => [key, value]);
57 * // => ['a', 1, 'b', 2]
58 */
59declare function flatMap<T extends object, R>(collection: T | null | undefined, iteratee: ObjectIterator<T, Many<R>>): R[];
60/**
61 * Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
62 *
63 * @param {object | null | undefined} collection - The collection to iterate over.
64 * @param {string} iteratee - The property name to use as iteratee.
65 * @returns {any[]} Returns the new flattened array.
66 *
67 * @example
68 * const users = [
69 * { user: 'barney', hobbies: ['hiking', 'coding'] },
70 * { user: 'fred', hobbies: ['reading'] }
71 * ];
72 * flatMap(users, 'hobbies');
73 * // => ['hiking', 'coding', 'reading']
74 */
75declare function flatMap(collection: object | null | undefined, iteratee: string): any[];
76/**
77 * Creates a flattened array of values by running each element in collection through iteratee and flattening the mapped results.
78 *
79 * @param {object | null | undefined} collection - The collection to iterate over.
80 * @param {object} iteratee - The object properties to match.
81 * @returns {boolean[]} Returns the new flattened array.
82 *
83 * @example
84 * const users = [
85 * { user: 'barney', age: 36, active: true },
86 * { user: 'fred', age: 40, active: false }
87 * ];
88 * flatMap(users, { active: false });
89 * // => [false]
90 */
91declare function flatMap(collection: object | null | undefined, iteratee: object): boolean[];
92
93export { flatMap };
Note: See TracBrowser for help on using the repository browser.