UNPKG

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