Ramda.js R.dropRepeatsBy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.dropRepeatsBy(fn, list) turns each item into a key with fn, then collapses every run of neighbouring items with equal keys into its first item (official Ramda docs). Keys are compared with R.equals, and the result holds the original items, not the keys.

Added in v0.29.0: R.dropRepeatsBy is stable — not deprecated, experimental, or non-standard. Note: it does not exist in older Ramda versions; there, use R.dropRepeatsWith(R.eqBy(fn)) instead.

Syntax

Call R.dropRepeatsBy. Start with this line.

Ramda
R.dropRepeatsBy(fn, list) or R.dropRepeatsBy(fn)(list)
CallWhat it does
R.dropRepeatsBy(fn, list) or R.dropRepeatsBy(fn)(list)Primary signature.
R.dropRepeatsBy(...)Call the list helper.

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

Library declarations
Ramda
R.dropRepeatsBy(fn, list) or R.dropRepeatsBy(fn)(list)

Parameters

ParameterDescription
fnRequired. Turns one item into the key used for comparing
listOptional. The array to clean up; omit it to get a reusable function

Return Value

Return ValueDescription
*A new array of original items, one per run of equal keys

Ramda Examples

Example 1 — Official Sample with Math.abs

Treat a number and its negative as the same key — the sample from the Ramda docs.

Ramda
const nums = [1, -1, -1, 2, 3, -4, 4, 2, 2];

console.log(R.dropRepeatsBy(Math.abs, nums));   // [1, 2, 3, -4, 2]
Try It Yourself

How It Works

  1. Keys. Math.abs turns the list into keys 1, 1, 1, 2, 3, 4, 4, 2, 2.
  2. Runs. 1, -1, -1 share key 1 and -4, 4 share key 4, so each run keeps one item.
  3. Original items. The first item of the key-4 run is -4, so -4 is kept, not 4.
  4. Neighbours only. The last 2 follows a 4, so it starts a new run and stays.

Example 2 — Ignore Letter Case

Collapse repeated answers even when they are typed in different cases.

Ramda
const answers = ['Yes', 'YES', 'no', 'No', 'yes'];

console.log(R.dropRepeatsBy(R.toLower, answers));   // ['Yes', 'no', 'yes']
Try It Yourself

How It Works

  1. Keys. R.toLower turns the answers into yes, yes, no, no, yes.
  2. Collapse. 'Yes', 'YES' become one item, and so do 'no', 'No'.
  3. Original text. The kept items keep their original spelling: 'Yes' and 'no'.
  4. New run. The final 'yes' follows a 'No', so it stays.

Example 3 — Collapse Records by a Property

Keep only the events where the status changed, using R.prop as the key.

Ramda
const events = [
  { id: 1, status: 'idle' },
  { id: 2, status: 'idle' },
  { id: 3, status: 'busy' },
  { id: 4, status: 'idle' }
];

const changes = R.dropRepeatsBy(R.prop('status'), events);

console.log(R.pluck('id', changes));   // [1, 3, 4]
Try It Yourself

How It Works

  1. Key. R.prop('status') reads each event’s status.
  2. Collapse. Events 1 and 2 are both 'idle', so only event 1 is kept.
  3. Changes. Event 3 switches to 'busy' and event 4 switches back to 'idle', so both stay.
  4. Show ids. R.pluck('id') lists the kept events’ ids: [1, 3, 4].

Example 4 — Keep Only Sign Changes

Use Math.sign to find where a series flips between positive, negative, and zero.

Ramda
const changes = [3, 5, -2, -7, 4, 0, 0];

const flips = R.dropRepeatsBy(Math.sign);

console.log(flips(changes));   // [3, -2, 4, 0]
Try It Yourself

How It Works

  1. Curried. R.dropRepeatsBy(Math.sign) returns a reusable flips function.
  2. Keys. Math.sign gives 1, 1, -1, -1, 1, 0, 0.
  3. Collapse. Each run of the same sign keeps its first number: 3, -2, 4, 0.
  4. Reading it. The series went up, then down, then up, then flat.

Example 5 — dropRepeatsBy vs dropRepeatsWith vs uniqBy

Same list, same key — see which helpers match and which one differs.

Ramda
const nums = [1, -1, -1, 2, 3, -4, 4, 2, 2];

console.log(R.dropRepeatsBy(Math.abs, nums));               // [1, 2, 3, -4, 2]
console.log(R.dropRepeatsWith(R.eqBy(Math.abs), nums));     // [1, 2, 3, -4, 2]
console.log(R.uniqBy(Math.abs, nums));                      // [1, 2, 3, -4]
Try It Yourself

How It Works

  1. dropRepeatsBy. Compares neighbours by Math.abs.
  2. Same thing. R.dropRepeatsWith with R.eqBy(Math.abs) gives an identical result — it is what dropRepeatsBy uses inside.
  3. uniqBy. R.uniqBy remembers every key it has seen, so the last 2 is dropped too.
  4. Choose. Use dropRepeatsBy for “what changed?” and uniqBy for “which distinct keys exist?”.

Browser & Runtime Support

R.dropRepeatsBy() is plain JavaScript inside Ramda 0.29.0+. It is built on R.dropRepeatsWith and R.eqBy, so it works wherever Ramda loads.

✓ Ramda 0.29.0+ · Any JS runtime

Ramda.js R.dropRepeatsBy()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun with require or import.

100% With Ramda 0.29+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.dropRepeatsBy() Universal

Bottom line: Safe in any project on Ramda 0.29 or newer; older versions have no R.dropRepeatsBy. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected].

Frequently Asked Questions

R.dropRepeatsBy(fn, list) turns each item into a key with fn, then collapses runs of neighbouring items whose keys are equal under R.equals. The official sample R.dropRepeatsBy(Math.abs, [1, -1, -1, 2, 3, -4, 4, 2, 2]) returns [1, 2, 3, -4, 2].
The original items. fn is only used for comparing neighbours, which is why the official result contains -4 rather than 4: -4 is the first item of its run.
R.dropRepeats compares items as they are. R.dropRepeatsBy compares fn(item). R.dropRepeatsWith takes a two-argument test. R.dropRepeatsBy(fn, list) gives the same result as R.dropRepeatsWith(R.eqBy(fn), list).
R.dropRepeatsBy only removes neighbours with the same key. R.uniqBy removes every later item whose key was already seen anywhere, so on the official list it returns [1, 2, 3, -4] instead of [1, 2, 3, -4, 2].
Your key function probably returns undefined (for example, a misspelled property name) or NaN for every item. Those keys are all equal under R.equals, so every item after the first counts as a repeat.
No. R.dropRepeatsBy was added in Ramda v0.29.0 and is stable. It is not deprecated, experimental, or non-standard, but it does not exist in Ramda versions older than 0.29.

Next: R.dropRepeatsWith()

Collapse consecutive items using your own equality test.

R.dropRepeatsWith() 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