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)
Call
What 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
Parameter
Description
f
Required. 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 Value
Description
Function
A 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.
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.
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.
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.
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.
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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.