Ramda’s R.intersection() answers a set-overlap question: which unique elements appear in both lists? You pass two lists of the same element type and get back a new array of shared values. Membership uses R.equals, so objects and nested arrays match by value. The result is a set — no duplicates. Order follows list1, not list2. It is not commutative when order differs. Cousin R.difference returns what is in the first list but not the second. Cousin R.innerJoin filters one list by a custom cross-list predicate and keeps duplicates from the first list. Previous helper is R.innerJoin. Next is R.lt.
The official sample is the whole idea. R.intersection([1,2,3,4], [7,6,5,4,3]) returns [4, 3] — values present in both lists, deduped, in the order they first appear when walking list1. On the same lists, R.difference([1,2,3,4], [7,6,5,4,3]) returns [1, 2].
Syntax
Call R.intersection. Start with this line.
Ramda
R.intersection(list1, list2)
Call
What it does
R.intersection(list1, list2)
Primary signature.
R.intersection(...)
Call the relation helper.
Prefer import { intersection } from "ramda" when you want a named import.
Library declarations
Ramda
R.intersection(list1, list2)
Parameters
Parameter
Description
list1
Required. Array. First list — shared elements are collected in this list's order. Not mutated.
list2
Required. Array. Second list — membership source. An element from list1 is kept when R.equals finds a match in list2. Not mutated.
Return Value
Return Value
Description
Array
A new array: the set of elements found in both list1 and list2. No duplicates. Empty overlap → [].
Ramda Examples
📚 Getting Started
The official Ramda number sample and how it contrasts with first-minus-second difference.
Example 1 — Official Number Sample
Find shared values between two number lists. Result order follows the first list.
That is the docs sample from ramdajs.com. 4 and 3 appear in both lists. They are returned in list1 order: 4 before 3 because that is how they appear in [1,2,3,4].
Example 2 — vs R.difference on the Same Lists
Intersection keeps shared values. Difference keeps unique items from the first list that are missing from the second.
Both helpers use R.equals for membership. Intersection answers “in both?” Difference answers “in first but not second?” On this input they are complementary: shared values vs unique leftovers from list1.
📈 Practical Patterns
innerJoin contrast, object overlap with R.equals, then curried partial application with R.__.
Example 3 — vs R.innerJoin — When Intersection Is Enough
For same-type lists, intersection dedupes with R.equals. innerJoin needs a predicate and keeps xs duplicates.
When both lists hold the same type and you want unique shared values, intersection is simpler. Use innerJoin when lists hold different shapes or when duplicates from the first list must stay. Previous helper walkthrough: R.innerJoin.
Example 4 — Object Overlap with R.equals
{a: 1} in the first list matches {a: 1} in the second even though they are different object identities.
Membership uses R.equals, not ===. The object from list1 is kept because its value equals an element in list2. {b: 2} has no match. Same pattern as R.difference object samples.
Example 5 — Curried Partial Application with R.__
Fix the second list once, then pass different first lists later.
R.intersection is arity 2 and supports R.__. R.intersection(R.__, allowlist) returns a function waiting for list1. Reuse the same overlap check against many incoming lists without repeating the fixed list.
Compatibility
Browser Support
R.intersection() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.1.0+ · Any JS runtime
Ramda.js R.intersection()
Load Ramda 0.1.0 or later via CDN or npm, then call R.intersection with two lists. No extra browser API is required.
100%With Ramda 0.1.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.intersection()Universal
Bottom line: Safe in any project that includes Ramda 0.1.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.intersection(list1, list2) returns a new array of elements found in both lists. Duplicates are removed. Type: [*] → [*] → [*]. Arity 2, curried. Added in v0.1.0.
R.intersection([1,2,3,4], [7,6,5,4,3]) returns [4, 3] — the shared values from both lists, deduped, in list1 order.
intersection keeps items in both lists. difference(list1, list2) keeps unique items from list1 that are not in list2. On the official sample, difference returns [1, 2] while intersection returns [4, 3]. Both use R.equals for membership.
intersection compares same-type lists with R.equals and dedupes. innerJoin takes a custom binary predicate, can join different shapes (records vs ids), preserves xs order and duplicates from xs.
No. Objects and arrays use R.equals (value equality). R.intersection([{a: 1}, {b: 2}], [{a: 1}, {c: 3}]) returns [{a: 1}] because {a: 1} matches by value.
No. R.intersection is a stable Ramda relation helper from v0.1.0. It is not deprecated, experimental, or non-standard.