UNPKG

@arrows/array

Version:
31 lines (30 loc) 843 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.flat = void 0; const curry_1 = require("@arrows/composition/curry"); const _flat = (depth, arr) => arr.flat(depth); const curriedFlat = curry_1.default(_flat); const flatOne = (arr) => arr.flat(); /** * Functional wrapper for Array.prototype.flat with custom depth * * Creates a new array with all sub-array elements * concatenated into it recursively up to the specified depth. * * @param depth Maximum recursion depth * @param arr Initial array * @returns New array * * @method one Version with default depth (1) */ const flat = Object.assign(curriedFlat, { /** * Version with default depth (1). * * @param arr Initial array * @returns New array */ one: flatOne, }); exports.flat = flat; exports.default = flat;