main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 | /**
|
---|
| 5 | * Takes a list and a predicate and returns a pair of lists with the following properties:
|
---|
| 6 | *
|
---|
| 7 | * - the result of concatenating the two output lists is equivalent to the input list;
|
---|
| 8 | * - none of the elements of the first output list satisfies the predicate; and
|
---|
| 9 | * - if the second output list is non-empty, its first element satisfies the predicate.
|
---|
| 10 | *
|
---|
| 11 | * @func
|
---|
| 12 | * @memberOf R
|
---|
| 13 | * @since v0.19.0
|
---|
| 14 | * @category List
|
---|
| 15 | * @sig (a -> Boolean) -> [a] -> [[a], [a]]
|
---|
| 16 | * @param {Function} pred The predicate that determines where the array is split.
|
---|
| 17 | * @param {Array} list The array to be split.
|
---|
| 18 | * @return {Array}
|
---|
| 19 | * @example
|
---|
| 20 | *
|
---|
| 21 | * R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]]
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | var splitWhen =
|
---|
| 26 | /*#__PURE__*/
|
---|
| 27 | _curry2(function splitWhen(pred, list) {
|
---|
| 28 | var idx = 0;
|
---|
| 29 | var len = list.length;
|
---|
| 30 | var prefix = [];
|
---|
| 31 |
|
---|
| 32 | while (idx < len && !pred(list[idx])) {
|
---|
| 33 | prefix.push(list[idx]);
|
---|
| 34 | idx += 1;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | return [prefix, Array.prototype.slice.call(list, idx)];
|
---|
| 38 | });
|
---|
| 39 |
|
---|
| 40 | module.exports = splitWhen; |
---|
Note:
See
TracBrowser
for help on using the repository browser.