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.

39 lines (38 loc) 2.08 kB
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } import { curry } from 'ramda'; import _makeFlat from './internal/makeFlat.js'; var flatten1 = _makeFlat(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 = curry(function (depth, list) { var currentDept = depth; var flatList = _toConsumableArray(list); while (currentDept > 0) { flatList = flatten1(flatList); currentDept -= 1; } return flatList; }); export default flattenDepth;