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.
58 lines (43 loc) • 2.42 kB
JavaScript
exports.__esModule = true;
exports["default"] = void 0;
var _ramda = require("ramda");
var _makeFlat2 = _interopRequireDefault(require("./internal/makeFlat"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; 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;
;