[d24f17c] | 1 | import _curry2 from "./internal/_curry2.js";
|
---|
| 2 | import _dispatchable from "./internal/_dispatchable.js";
|
---|
| 3 | import _xdropRepeatsWith from "./internal/_xdropRepeatsWith.js";
|
---|
| 4 | import last from "./last.js";
|
---|
| 5 | /**
|
---|
| 6 | * Returns a new list without any consecutively repeating elements. Equality is
|
---|
| 7 | * determined by applying the supplied predicate to each pair of consecutive elements. The
|
---|
| 8 | * first element in a series of equal elements will be preserved.
|
---|
| 9 | *
|
---|
| 10 | * Acts as a transducer if a transformer is given in list position.
|
---|
| 11 | *
|
---|
| 12 | * @func
|
---|
| 13 | * @memberOf R
|
---|
| 14 | * @since v0.14.0
|
---|
| 15 | * @category List
|
---|
| 16 | * @sig ((a, a) -> Boolean) -> [a] -> [a]
|
---|
| 17 | * @param {Function} pred A predicate used to test whether two items are equal.
|
---|
| 18 | * @param {Array} list The array to consider.
|
---|
| 19 | * @return {Array} `list` without repeating elements.
|
---|
| 20 | * @see R.transduce
|
---|
| 21 | * @example
|
---|
| 22 | *
|
---|
| 23 | * const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
|
---|
| 24 | * R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3]
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | var dropRepeatsWith =
|
---|
| 28 | /*#__PURE__*/
|
---|
| 29 | _curry2(
|
---|
| 30 | /*#__PURE__*/
|
---|
| 31 | _dispatchable([], _xdropRepeatsWith, function dropRepeatsWith(pred, list) {
|
---|
| 32 | var result = [];
|
---|
| 33 | var idx = 1;
|
---|
| 34 | var len = list.length;
|
---|
| 35 |
|
---|
| 36 | if (len !== 0) {
|
---|
| 37 | result[0] = list[0];
|
---|
| 38 |
|
---|
| 39 | while (idx < len) {
|
---|
| 40 | if (!pred(last(result), list[idx])) {
|
---|
| 41 | result[result.length] = list[idx];
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | idx += 1;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | return result;
|
---|
| 49 | }));
|
---|
| 50 |
|
---|
| 51 | export default dropRepeatsWith; |
---|