Ramda.js R.complement() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Logic

Definition

Ramda’s R.complement() answers a logic question: what is the opposite of this test? You pass one function. You get back one function. Call that leftover with the same arguments. If the original leftover is truthy, you get false. If it is falsy, you get true. Native JavaScript would write (...args) => !f(...args). complement names that flip once, keeps the original arity, and always returns a boolean. Drop the leftover into R.filter and R.find.

The official sample is the whole idea. R.isNil is true for null and undefined. R.complement(R.isNil) is the opposite: false for null, true for 7. Need to flip a value, not a function? That is R.not. Need to drop items that pass a test? That is R.reject, which is filter plus complement. Previous Logic helper is R.both. Next is R.cond.

Syntax

Call R.complement. Start with this line.

Ramda
R.complement(f)
CallWhat it does
R.complement(f)Primary signature.
R.complement(...)Call the logic helper.

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

Library declarations
Ramda
R.complement(f)

Parameters

ParameterDescription
fRequired. Function. Any function. Called with the same arguments you later pass to the leftover. Truthy leftovers become false. Falsy leftovers become true.

Return Value

Return ValueDescription
FunctionA curried leftover. It returns !f(…) as a boolean. The leftover's arity matches f.length.

Ramda Examples

📚 Getting Started

The official Ramda isNotNil sample, then the same idea compared with not, reject, and filter.

Example 1 — Official isNotNil

The leftover sees the same value as isNil. Truthy isNil becomes false. Falsy isNil becomes true.

Ramda
const isNotNil = R.complement(R.isNil);

R.isNil(null);
//=> true

isNotNil(null);
//=> false

R.isNil(7);
//=> false

isNotNil(7);
//=> true
Try It Yourself

How It Works

null is nil, so the opposite is false. 7 is not nil, so the opposite is true. That is the docs sample from ramdajs.com. Name the leftover once and reuse it.

Example 2 — vs not, reject, and filter

not flips a value. complement flips a function. reject drops items that pass a test. filter keeps items that pass the opposite test.

Ramda
R.not(R.isNil(null));
//=> false

R.complement(R.isNil)(null);
//=> false

R.reject(R.isNil, [1, null, 2]);
//=> [1, 2]

R.filter(R.complement(R.isNil), [1, null, 2]);
//=> [1, 2]
Try It Yourself

How It Works

R.not(R.isNil(null)) first calls isNil, then flips the boolean. complement wraps the function so you can pass it around. reject and filter with complement keep the same two numbers.

📈 Practical Patterns

Falsy leftovers become true, then filter and find, then a leftover whose arity is 2.

Example 3 — Falsy Leftovers Become True

complement always returns a boolean. Any falsy leftover from f becomes true.

Ramda
const isFalsy = R.complement(R.identity);

isFalsy('');
//=> true

isFalsy(0);
//=> true

isFalsy('hi');
//=> false

isFalsy(1);
//=> false
Try It Yourself

How It Works

R.identity returns the value unchanged. Logical not then turns '' and 0 into true, and turns 'hi' and 1 into false. Unlike R.both, the leftover is never a string.

Example 4 — Filter and Find

Keep tickets that are not done. Find the first open ticket.

Ramda
const isOpen = R.complement(R.propEq('done', 'status'));

const rows = [
  { id: 1, status: 'done' },
  { id: 2, status: 'open' },
  { id: 3, status: 'open' }
];

R.filter(isOpen, rows);
//=> [{ id: 2, status: 'open' }, { id: 3, status: 'open' }]

R.find(isOpen, rows);
//=> { id: 2, status: 'open' }
Try It Yourself

How It Works

Filling complement leaves a function of one object for R.filter and R.find. Row 1 is done, so it fails the opposite test. Rows 2 and 3 pass. R.reject(R.propEq('done', 'status'), rows) would keep the same pair.

Example 5 — Binary Leftover

The leftover arity matches the original function. Unapplied R.equals still waits for two values.

Ramda
const neq = R.complement(R.equals);

neq(1, 1);
//=> false

neq(1, 2);
//=> true

neq(1)(2);
//=> true
Try It Yourself

How It Works

R.equals has .length 2, so neq is still curried of arity 2. Equal values make equals true, so complement is false. Unequal values flip to true. You can still fill one argument at a time.

Browser Support

R.complement() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.12.0+ · Any JS runtime

Ramda.js R.complement()

Load Ramda 0.12.0 or later via CDN or npm, then call R.complement with a function. No extra browser API is required.

100% With Ramda 0.12.0+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.complement() Universal

Bottom line: Safe in any project that includes Ramda 0.12.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.complement(f) takes a function f and returns a new function g. Call g with the same arguments: if f is truthy, g is false; if f is falsy, g is true. The leftover is always a boolean. Added in v0.12.0. Type: (*… → *) → (*… → Boolean).
isNotNil = R.complement(R.isNil). R.isNil(null) is true, so isNotNil(null) is false. R.isNil(7) is false, so isNotNil(7) is true.
not flips a value: R.not(true) is false. complement flips a function: R.complement(R.isNil) is a new predicate. reject(pred, list) keeps items that fail pred — the same idea as filter(complement(pred), list).
Yes. complement uses logical not, so the leftover is boolean. R.complement(R.identity)('') is true because '' is falsy. R.complement(R.identity)('hi') is false because 'hi' is truthy.
It matches f.length. R.complement(R.isNil) has arity 1. R.complement(R.equals) has arity 2, so it still waits for two values.
No. R.complement is a stable Ramda logic helper from v0.12.0. It is not deprecated, experimental, or non-standard.

Continue to R.cond()

Learn how to pick a branch from a list of tests with Ramda R.cond().

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