source: node_modules/ramda/es/splitWhen.js

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.0 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2/**
3 * Takes a list and a predicate and returns a pair of lists with the following properties:
4 *
5 * - the result of concatenating the two output lists is equivalent to the input list;
6 * - none of the elements of the first output list satisfies the predicate; and
7 * - if the second output list is non-empty, its first element satisfies the predicate.
8 *
9 * @func
10 * @memberOf R
11 * @since v0.19.0
12 * @category List
13 * @sig (a -> Boolean) -> [a] -> [[a], [a]]
14 * @param {Function} pred The predicate that determines where the array is split.
15 * @param {Array} list The array to be split.
16 * @return {Array}
17 * @example
18 *
19 * R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]]
20 */
21
22var splitWhen =
23/*#__PURE__*/
24_curry2(function splitWhen(pred, list) {
25 var idx = 0;
26 var len = list.length;
27 var prefix = [];
28
29 while (idx < len && !pred(list[idx])) {
30 prefix.push(list[idx]);
31 idx += 1;
32 }
33
34 return [prefix, Array.prototype.slice.call(list, idx)];
35});
36
37export default splitWhen;
Note: See TracBrowser for help on using the repository browser.