| 1 | import { ListIterator } from '../_internal/ListIterator.js';
|
|---|
| 2 | import { Many } from '../_internal/Many.js';
|
|---|
| 3 | import { ObjectIterator } from '../_internal/ObjectIterator.js';
|
|---|
| 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 | */
|
|---|
| 17 | declare 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 | */
|
|---|
| 28 | declare 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 | */
|
|---|
| 45 | declare 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 | */
|
|---|
| 59 | declare 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 | */
|
|---|
| 75 | declare 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 | */
|
|---|
| 91 | declare function flatMap(collection: object | null | undefined, iteratee: object): boolean[];
|
|---|
| 92 |
|
|---|
| 93 | export { flatMap };
|
|---|