UNPKG

ramda-adjunct

Version:

Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.

54 lines (41 loc) 1.81 kB
"use strict"; exports.__esModule = true; exports["default"] = void 0; var _ramda = require("ramda"); var _makeFlat2 = _interopRequireDefault(require("ramda/src/internal/_makeFlat")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } var flatten1 = (0, _makeFlat2["default"])(false); /** * Flattens the list to the specified depth. * * @func flattenDepth * @memberOf RA * @since {@link https://char0n.github.io/ramda-adjunct/2.19.0|v2.19.0} * @category List * @sig Number -> [a] -> [b] * @param {!number} depth The maximum recursion depth * @param {!Array} list The array to flatten * @return {!Array} Returns the new flattened array * @see {@link http://ramdajs.com/docs/#flatten|R.flatten}, {@link http://ramdajs.com/docs/#unnest|R.unnest} * @example * * RA.flattenDepth( * 2, * [1, [2], [3, [4, 5], 6, [[[7], 8]]], 9, 10] * ); //=> [1, 2, 3, 4, 5, 6, [[7], 8], 9, 10]; */ var flattenDepth = (0, _ramda.curry)(function (depth, list) { var currentDept = depth; var flatList = _toConsumableArray(list); while (currentDept > 0) { flatList = flatten1(flatList); currentDept -= 1; } return flatList; }); var _default = flattenDepth; exports["default"] = _default;