mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/splitWhen.js
|
|
|
|
|
|
import _curry2 from './internal/_curry2.js';
|
|
|
|
|
|
/**
|
|
* Takes a list and a predicate and returns a pair of lists with the following properties:
|
|
*
|
|
* - the result of concatenating the two output lists is equivalent to the input list;
|
|
* - none of the elements of the first output list satisfies the predicate; and
|
|
* - if the second output list is non-empty, its first element satisfies the predicate.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.19.0
|
|
* @category List
|
|
* @sig (a -> Boolean) -> [a] -> [[a], [a]]
|
|
* @param {Function} pred The predicate that determines where the array is split.
|
|
* @param {Array} list The array to be split.
|
|
* @return {Array}
|
|
* @example
|
|
*
|
|
* R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]]
|
|
*/
|
|
var splitWhen = _curry2(function splitWhen(pred, list) {
|
|
var idx = 0;
|
|
var len = list.length;
|
|
var prefix = [];
|
|
|
|
while (idx < len && !pred(list[idx])) {
|
|
prefix.push(list[idx]);
|
|
idx += 1;
|
|
}
|
|
|
|
return [prefix, Array.prototype.slice.call(list, idx)];
|
|
});
|
|
export default splitWhen;
|