insertAll.js 1005 B

12345678910111213141516171819202122232425262728
  1. import _curry3 from "./internal/_curry3.js";
  2. /**
  3. * Inserts the sub-list into the list, at the specified `index`. _Note that this is not
  4. * destructive_: it returns a copy of the list with the changes.
  5. * <small>No lists have been harmed in the application of this function.</small>
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.9.0
  10. * @category List
  11. * @sig Number -> [a] -> [a] -> [a]
  12. * @param {Number} index The position to insert the sub-list
  13. * @param {Array} elts The sub-list to insert into the Array
  14. * @param {Array} list The list to insert the sub-list into
  15. * @return {Array} A new Array with `elts` inserted starting at `index`.
  16. * @example
  17. *
  18. * R.insertAll(2, ['x','y','z'], [1,2,3,4]); //=> [1,2,'x','y','z',3,4]
  19. */
  20. var insertAll =
  21. /*#__PURE__*/
  22. _curry3(function insertAll(idx, elts, list) {
  23. idx = idx < list.length && idx >= 0 ? idx : list.length;
  24. return [].concat(Array.prototype.slice.call(list, 0, idx), elts, Array.prototype.slice.call(list, idx));
  25. });
  26. export default insertAll;