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.

48 lines
1.4 KiB

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. import _dispatchable from "./internal/_dispatchable.js";
  3. import _xdropWhile from "./internal/_xdropWhile.js";
  4. import slice from "./slice.js";
  5. /**
  6. * Returns a new list excluding the leading elements of a given list which
  7. * satisfy the supplied predicate function. It passes each value to the supplied
  8. * predicate function, skipping elements while the predicate function returns
  9. * `true`. The predicate function is applied to one argument: *(value)*.
  10. *
  11. * Dispatches to the `dropWhile` method of the second argument, if present.
  12. *
  13. * Acts as a transducer if a transformer is given in list position.
  14. *
  15. * @func
  16. * @memberOf R
  17. * @since v0.9.0
  18. * @category List
  19. * @sig (a -> Boolean) -> [a] -> [a]
  20. * @sig (a -> Boolean) -> String -> String
  21. * @param {Function} fn The function called per iteration.
  22. * @param {Array} xs The collection to iterate over.
  23. * @return {Array} A new array.
  24. * @see R.takeWhile, R.transduce, R.addIndex
  25. * @example
  26. *
  27. * const lteTwo = x => x <= 2;
  28. *
  29. * R.dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]); //=> [3, 4, 3, 2, 1]
  30. *
  31. * R.dropWhile(x => x !== 'd' , 'Ramda'); //=> 'da'
  32. */
  33. var dropWhile =
  34. /*#__PURE__*/
  35. _curry2(
  36. /*#__PURE__*/
  37. _dispatchable(['dropWhile'], _xdropWhile, function dropWhile(pred, xs) {
  38. var idx = 0;
  39. var len = xs.length;
  40. while (idx < len && pred(xs[idx])) {
  41. idx += 1;
  42. }
  43. return slice(idx, Infinity, xs);
  44. }));
  45. export default dropWhile;