Ramda.js R.dropRepeatsWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A list helper that removes consecutive repeats, where you decide what “repeat” means. You pass a two-argument test; when it returns true, the later neighbour is dropped. The first item of every run stays, and the original list is never changed. Part of Ramda List since v0.14.0 (stable — not deprecated, experimental, or non-standard).

Why a custom test? R.dropRepeats only knows exact equality. With dropRepeatsWith, -4 and 4, "A" and "a", or two rows with the same status can count as the same thing.

Syntax

Call R.dropRepeatsWith. Start with this line.

Ramda
R.dropRepeatsWith(pred, list)
CallWhat it does
R.dropRepeatsWith(pred, list)Primary signature.
R.dropRepeatsWith(...)Call the list helper.

Prefer import { dropRepeatsWith } from "ramda" when you want a named import.

Library declarations
Ramda
R.dropRepeatsWith(pred, list)

Parameters

ParameterDescription
predRequired. (a, b) → Boolean — truthy means "same"
listRequired. The array to clean

Return Value

Return ValueDescription
*A new array with the first item of each run

Ramda Examples

Example 1 — Official Same-Absolute-Value Test

Treat 4 and -4 as the same, then drop neighbouring repeats.

Ramda
const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];

console.log(R.dropRepeatsWith(R.eqBy(Math.abs), l));
// → [1, 3, 4, -5, 3]
Try It Yourself

How It Works

  1. Build the test. R.eqBy(Math.abs) returns (a, b) => Math.abs(a) === Math.abs(b). Math.abs drops the sign.
  2. Keep the first. 1 goes straight into the result.
  3. Skip the same. -1 and 1 have the same absolute value as 1, so they are dropped. The same happens to both -4s after 4.
  4. Originals stay. -5 is kept as -5; the test only compares, it never changes items.
  5. Neighbours only. The last-but-one 3 follows -5, so it starts a new run and stays.

Example 2 — Your Own Two-Argument Test

Collapse repeated key presses, ignoring upper and lower case.

Ramda
function sameLetter(a, b) {
  return a.toLowerCase() === b.toLowerCase();
}

const keys = ["a", "A", "b", "B", "b", "a"];

console.log(R.dropRepeatsWith(sameLetter, keys));
// → ["a", "b", "a"]
Try It Yourself

How It Works

  1. The question. sameLetter(a, b) answers “are these the same?” using toLowerCase() on both sides.
  2. First run. Keep "a"; "A" is the same letter → skip.
  3. Second run. "b" differs from "a" → keep; "B" and "b" → skip.
  4. Third run. The final "a" differs from the last kept "b" → keep. Result: ["a", "b", "a"].

Example 3 — Compare Objects by One Field

Turn a status log into a list of changes with R.eqProps.

Ramda
const log = [
  { time: "09:00", status: "online" },
  { time: "09:05", status: "online" },
  { time: "09:10", status: "offline" },
  { time: "09:15", status: "offline" },
  { time: "09:20", status: "online" }
];

const changes = R.dropRepeatsWith(R.eqProps("status"), log);

console.log(R.pluck("time", changes));
// → ["09:00", "09:10", "09:20"]
Try It Yourself

How It Works

  1. Field test. R.eqProps("status") returns a pair test: (a, b) => R.equals(a.status, b.status).
  2. Runs collapse. 09:05 has the same status as 09:00 → skip; 09:15 matches 09:10 → skip.
  3. Whole objects kept. The result holds the original first row of each run, time included.
  4. Show it. R.pluck("time", changes) lists when each change happened.

Example 4 — Tolerance Test Compares with the Last Kept

Ignore small sensor jitter. Note which item sits on the left of each comparison.

Ramda
const closeEnough = (a, b) => Math.abs(a - b) <= 2;

const readings = [100, 101, 102, 104, 105];

console.log(R.dropRepeatsWith(closeEnough, readings));
// → [100, 104]
Try It Yourself

How It Works

  1. Keep 100. It becomes the last kept item.
  2. Skip 101 and 102. Both are compared with 100 (gaps 1 and 2) → close enough → skip.
  3. Keep 104. It is compared with 100, not 102. The gap is 4 → keep.
  4. Skip 105. Compared with the new last kept 104 → gap 1 → skip. Result: [100, 104].

Example 5 — Curried Helper vs R.uniqWith

Build a reusable cleaner, then see how it differs from removing repeats everywhere.

Ramda
const sameWord = R.eqBy(R.toLower);
const collapseRuns = R.dropRepeatsWith(sameWord);

const words = ["red", "Red", "blue", "RED", "blue"];

console.log(collapseRuns(words));
// → ["red", "blue", "RED", "blue"]

console.log(R.uniqWith(sameWord, words));
// → ["red", "blue"]
Try It Yourself

How It Works

  1. Curried. Passing only the test returns collapseRuns, a function waiting for a list.
  2. Case-insensitive test. R.toLower inside R.eqBy makes "red", "Red", and "RED" equal.
  3. Neighbours only. "Red" is dropped (it follows "red"), but "RED" follows "blue", so it stays.
  4. Everywhere. R.uniqWith drops a word if it appeared anywhere earlier, leaving ["red", "blue"].

Browser & Runtime Support

R.dropRepeatsWith is a Ramda List helper since v0.14.0. It uses only basic array indexing, so it runs anywhere Ramda runs — browsers via CDN or bundler, and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.14.0+

R.dropRepeatsWith()

Support depends on the Ramda version you load, not on a browser feature. Your own test function must also be valid in that runtime — e.g. arrow functions need an ES2015 engine.

100% Modern browsers & runtimes
Google Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Chromium-based
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Android WebView Modern WebView
Full support
Internet Explorer Not a target for current Ramda releases
Legacy
Node.js Maintained LTS · npm install ramda
Supported
Bun import from "ramda"
Supported
Deno import from "npm:ramda"
Supported
R.dropRepeatsWith Ramda 0.14.0+

Bottom line: Safe for production in any modern browser or JavaScript runtime once Ramda is loaded. The labs on this page use [email protected] from a CDN.

Frequently Asked Questions

R.dropRepeatsWith(pred, list) returns a new list without consecutive repeats, where your predicate decides what counts as a repeat. The first item of each run is kept. The docs sample is R.dropRepeatsWith(R.eqBy(Math.abs), [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3]) //=> [1, 3, 4, -5, 3].
A truthy result means the two items are equal, so the later one is dropped. A falsy result keeps it. This is the opposite of R.filter, where true means keep.
It compares the last item already kept with the next item in the list: pred(lastKept, next). After a skip, the last kept item stays the same, so the next comparison is still against it — not against the item that was just skipped.
R.dropRepeats(list) is R.dropRepeatsWith(R.equals, list). R.dropRepeatsBy(fn, list) is R.dropRepeatsWith(R.eqBy(fn), list). Use dropRepeatsWith when your rule needs both items at once, such as a tolerance check or a field comparison.
dropRepeatsWith only removes neighbours, so a value can come back after a different one. R.uniqWith removes repeats anywhere in the list. For ['red', 'blue', 'red'] with R.equals, dropRepeatsWith keeps all three; uniqWith returns ['red', 'blue'].
No. R.dropRepeatsWith has been part of Ramda since v0.14.0 and is stable — not deprecated, experimental, or non-standard.

Next: R.dropWhile()

Learn how to skip items from the start of a list while a condition holds.

R.dropWhile() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful