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.

33 lines
900 B

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. import always from "./always.js";
  3. import times from "./times.js";
  4. /**
  5. * Returns a fixed list of size `n` containing a specified identical value.
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.1.1
  10. * @category List
  11. * @sig a -> n -> [a]
  12. * @param {*} value The value to repeat.
  13. * @param {Number} n The desired size of the output list.
  14. * @return {Array} A new array containing `n` `value`s.
  15. * @see R.times
  16. * @example
  17. *
  18. * R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi']
  19. *
  20. * const obj = {};
  21. * const repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}]
  22. * repeatedObjs[0] === repeatedObjs[1]; //=> true
  23. * @symb R.repeat(a, 0) = []
  24. * @symb R.repeat(a, 1) = [a]
  25. * @symb R.repeat(a, 2) = [a, a]
  26. */
  27. var repeat =
  28. /*#__PURE__*/
  29. _curry2(function repeat(value, n) {
  30. return times(always(value), n);
  31. });
  32. export default repeat;