[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var _dispatchable =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_dispatchable.js");
|
---|
| 8 |
|
---|
| 9 | var _xtakeWhile =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./internal/_xtakeWhile.js");
|
---|
| 12 |
|
---|
| 13 | var slice =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./slice.js");
|
---|
| 16 | /**
|
---|
| 17 | * Returns a new list containing the first `n` elements of a given list,
|
---|
| 18 | * passing each value to the supplied predicate function, and terminating when
|
---|
| 19 | * the predicate function returns `false`. Excludes the element that caused the
|
---|
| 20 | * predicate function to fail. The predicate function is passed one argument:
|
---|
| 21 | * *(value)*.
|
---|
| 22 | *
|
---|
| 23 | * Dispatches to the `takeWhile` method of the second argument, if present.
|
---|
| 24 | *
|
---|
| 25 | * Acts as a transducer if a transformer is given in list position.
|
---|
| 26 | *
|
---|
| 27 | * @func
|
---|
| 28 | * @memberOf R
|
---|
| 29 | * @since v0.1.0
|
---|
| 30 | * @category List
|
---|
| 31 | * @sig (a -> Boolean) -> [a] -> [a]
|
---|
| 32 | * @sig (a -> Boolean) -> String -> String
|
---|
| 33 | * @param {Function} fn The function called per iteration.
|
---|
| 34 | * @param {Array} xs The collection to iterate over.
|
---|
| 35 | * @return {Array} A new array.
|
---|
| 36 | * @see R.dropWhile, R.transduce, R.addIndex
|
---|
| 37 | * @example
|
---|
| 38 | *
|
---|
| 39 | * const isNotFour = x => x !== 4;
|
---|
| 40 | *
|
---|
| 41 | * R.takeWhile(isNotFour, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3]
|
---|
| 42 | *
|
---|
| 43 | * R.takeWhile(x => x !== 'd' , 'Ramda'); //=> 'Ram'
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | var takeWhile =
|
---|
| 48 | /*#__PURE__*/
|
---|
| 49 | _curry2(
|
---|
| 50 | /*#__PURE__*/
|
---|
| 51 | _dispatchable(['takeWhile'], _xtakeWhile, function takeWhile(fn, xs) {
|
---|
| 52 | var idx = 0;
|
---|
| 53 | var len = xs.length;
|
---|
| 54 |
|
---|
| 55 | while (idx < len && fn(xs[idx])) {
|
---|
| 56 | idx += 1;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | return slice(0, idx, xs);
|
---|
| 60 | }));
|
---|
| 61 |
|
---|
| 62 | module.exports = takeWhile; |
---|