Ramda.js R.partition() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A list function that splits one list into two groups with a single test. R.partition(fn, list) returns [pass, fail]: the items where fn is true, then the items where it is false. Every item lands in exactly one group, and the original list is not changed.

Status: stable since Ramda v0.1.4 — not deprecated, experimental, or non-standard.

Syntax

Call R.partition. Start with this line.

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

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

Library declarations
Ramda
R.partition(fn, list)

Parameters

ParameterDescription
fnRequired. Test function, called with one item (or one object value)
listRequired. An array or a plain object (never changed)

Return Value

Return ValueDescription
*[pass, fail] — two arrays, or two objects

Ramda Examples

Example 1 — Official: Words With an "s"

The array sample from the Ramda docs.

Ramda
const words = ["sss", "ttt", "foo", "bars"];

console.log(R.partition(R.includes("s"), words));
// → [["sss", "bars"], ["ttt", "foo"]]
Try It Yourself

How It Works

  1. Test. R.includes("s") asks “does this word contain an s?”
  2. Sort. "sss" and "bars" say yes; "ttt" and "foo" say no.
  3. Result. The yes group comes first, the no group second, each in the original order.

Example 2 — Official: Split an Object by Its Values

The same test on an object keeps each key with its value.

Ramda
const obj = { a: "sss", b: "ttt", foo: "bars" };

console.log(R.partition(R.includes("s"), obj));
// → [{ a: "sss", foo: "bars" }, { b: "ttt" }]
Try It Yourself

How It Works

  1. Values. The test sees "sss", "ttt", and "bars" — not the keys.
  2. Keep keys. Each passing value goes into the first object under its original key.
  3. Result. Two objects: { a, foo } passed and { b } failed.

Example 3 — Passed and Failed Scores

Destructure the pair straight into two named variables.

Ramda
const scores = [72, 45, 90, 30];
const [passed, failed] = R.partition(score => score >= 50, scores);

console.log(passed);   // → [72, 90]
console.log(failed);   // → [45, 30]
Try It Yourself

How It Works

  1. Test. score >= 50 is true for 72 and 90.
  2. Split. R.partition returns [[72, 90], [45, 30]].
  3. Unpack. const [passed, failed] names the two groups in one line.

Example 4 — Done and To-Do Tasks

Split a list of objects by a true / false property.

Ramda
const tasks = [
  { title: "Write", done: true },
  { title: "Test", done: false },
  { title: "Ship", done: true }
];
const [done, todo] = R.partition(R.prop("done"), tasks);

console.log(R.pluck("title", done));   // → ["Write", "Ship"]
console.log(R.pluck("title", todo));   // → ["Test"]
Try It Yourself

How It Works

  1. Test. R.prop("done") reads each task’s done flag.
  2. Split. Tasks with true go to done; the rest go to todo.
  3. Show. R.pluck("title") lists just the titles of each group.

Example 5 — A Reusable Even / Odd Splitter

R.partition is curried, so give it the test now and the list later.

Ramda
const splitEvens = R.partition(n => n % 2 === 0);

console.log(splitEvens([1, 2, 3, 4]));   // → [[2, 4], [1, 3]]
console.log(splitEvens([]));             // → [[], []]
Try It Yourself

How It Works

  1. Partial call. R.partition(fn) returns a function still waiting for a list.
  2. Reuse. splitEvens puts evens first and odds second.
  3. Empty. An empty list still gives two groups: [[], []], so destructuring never breaks.

Browser & Runtime Support

R.partition has been in Ramda since v0.1.4. Ramda’s browser build is plain ES5, so it runs in any modern browser and in Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.1.4+

R.partition()

Built from Ramda’s own filter and reject, so no special browser API is needed. It works on arrays, plain objects, and any value with a filter method.

100% With any Ramda version
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.partition Ramda 0.1.4+

Bottom line: Safe for production with any Ramda release. The labs on this page use [email protected].

Frequently Asked Questions

R.partition(fn, list) splits a list into two groups and returns them as [pass, fail]: first the items where fn is true, then the items where fn is false. Docs sample: R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']) //=> [['sss', 'bars'], ['ttt', 'foo']].
R.filter keeps only the passing items and R.reject keeps only the failing ones. R.partition gives you both groups at once, as a two-item array. Internally it is R.juxt([R.filter, R.reject]).
Yes. It tests each value and keeps the keys: R.partition(R.includes('s'), {a: 'sss', b: 'ttt', foo: 'bars'}) is [{a: 'sss', foo: 'bars'}, {b: 'ttt'}].
[[], []] — always two groups, even when both are empty. An empty object gives [{}, {}].
Twice per item, because R.partition runs R.filter and then R.reject over the whole list. Keep the test fast and free of side effects.
No. R.partition has been a stable Ramda list function since v0.1.4 — not deprecated, experimental, or non-standard.

Next: R.pluck()

Learn how to pull one property out of every object in a list.

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