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.

35 lines
1.2 KiB

4 years ago
  1. import _checkForMethod from "./internal/_checkForMethod.js";
  2. import _curry3 from "./internal/_curry3.js";
  3. /**
  4. * Returns the elements of the given list or string (or object with a `slice`
  5. * method) from `fromIndex` (inclusive) to `toIndex` (exclusive).
  6. *
  7. * Dispatches to the `slice` method of the third argument, if present.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.1.4
  12. * @category List
  13. * @sig Number -> Number -> [a] -> [a]
  14. * @sig Number -> Number -> String -> String
  15. * @param {Number} fromIndex The start index (inclusive).
  16. * @param {Number} toIndex The end index (exclusive).
  17. * @param {*} list
  18. * @return {*}
  19. * @example
  20. *
  21. * R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
  22. * R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
  23. * R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c']
  24. * R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
  25. * R.slice(0, 3, 'ramda'); //=> 'ram'
  26. */
  27. var slice =
  28. /*#__PURE__*/
  29. _curry3(
  30. /*#__PURE__*/
  31. _checkForMethod('slice', function slice(fromIndex, toIndex, list) {
  32. return Array.prototype.slice.call(list, fromIndex, toIndex);
  33. }));
  34. export default slice;