@arrows/array
Version:
Functional tools for JS arrays
19 lines (18 loc) • 691 B
TypeScript
declare type MappingFn<V> = (currentValue: V, index?: number, array?: V[]) => unknown;
declare type _FlatMap = <T>(mappingFn: MappingFn<T>, arr: T[]) => unknown[];
declare type _FlatMap2 = <T>(mappingFn: MappingFn<T>) => (arr: T[]) => unknown[];
declare type FlatMap = _FlatMap & _FlatMap2;
/**
* Functional wrapper for Array.prototype.flatMap
*
* Calls a defined mapping function on each element of an array.
* Then, flattens the result into a new array.
* This is identical to a map followed by flat with depth 1.
*
* @param mappingFn Mapping function
* @param arr Initial array
* @returns New array
*/
declare const flatMap: FlatMap;
export { flatMap };
export default flatMap;