swc/crates/swc_bundler/tests/.cache/deno/15e012f58ce28a8f6da346ff8bfcd6e41d822f0e.ts
2021-11-09 20:42:49 +09:00

47 lines
1.4 KiB
TypeScript

// Loaded from https://deno.land/x/ramda@v0.27.2/source/dropRepeatsWith.js
import _curry2 from './internal/_curry2.js';
import _dispatchable from './internal/_dispatchable.js';
import _xdropRepeatsWith from './internal/_xdropRepeatsWith.js';
import last from './last.js';
/**
* Returns a new list without any consecutively repeating elements. Equality is
* determined by applying the supplied predicate to each pair of consecutive elements. The
* first element in a series of equal elements will be preserved.
*
* Acts as a transducer if a transformer is given in list position.
*
* @func
* @memberOf R
* @since v0.14.0
* @category List
* @sig ((a, a) -> Boolean) -> [a] -> [a]
* @param {Function} pred A predicate used to test whether two items are equal.
* @param {Array} list The array to consider.
* @return {Array} `list` without repeating elements.
* @see R.transduce
* @example
*
* const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
* R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3]
*/
var dropRepeatsWith = _curry2(_dispatchable([], _xdropRepeatsWith, function dropRepeatsWith(pred, list) {
var result = [];
var idx = 1;
var len = list.length;
if (len !== 0) {
result[0] = list[0];
while (idx < len) {
if (!pred(last(result), list[idx])) {
result[result.length] = list[idx];
}
idx += 1;
}
}
return result;
}));
export default dropRepeatsWith;