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 |
|
---|
34 | var dropWhile =
|
---|
35 | /*#__PURE__*/
|
---|
36 | _curry2(
|
---|
37 | /*#__PURE__*/
|
---|
38 | _dispatchable(['dropWhile'], _xdropWhile, function dropWhile(pred, xs) {
|
---|
39 | var idx = 0;
|
---|
40 | var len = xs.length;
|
---|
41 |
|
---|
42 | while (idx < len && pred(xs[idx])) {
|
---|
43 | idx += 1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | return slice(idx, Infinity, xs);
|
---|
47 | }));
|
---|
48 |
|
---|
49 | export default dropWhile; |
---|