You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
836 B

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. import length from "./length.js";
  3. import slice from "./slice.js";
  4. /**
  5. * Splits a given list or string at a given index.
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.19.0
  10. * @category List
  11. * @sig Number -> [a] -> [[a], [a]]
  12. * @sig Number -> String -> [String, String]
  13. * @param {Number} index The index where the array/string is split.
  14. * @param {Array|String} array The array/string to be split.
  15. * @return {Array}
  16. * @example
  17. *
  18. * R.splitAt(1, [1, 2, 3]); //=> [[1], [2, 3]]
  19. * R.splitAt(5, 'hello world'); //=> ['hello', ' world']
  20. * R.splitAt(-1, 'foobar'); //=> ['fooba', 'r']
  21. */
  22. var splitAt =
  23. /*#__PURE__*/
  24. _curry2(function splitAt(index, array) {
  25. return [slice(0, index, array), slice(index, length(array), array)];
  26. });
  27. export default splitAt;