Ramda.js Introduction

What Is Ramda.js?
Ramda is a practical functional programming library for JavaScript. Its helpers are automatically curried, data-last, and immutable—they return new values instead of mutating inputs.
Convention: import as R
const R = require('ramda')
import * as R from 'ramda'
Style:
config / transform first → data last
R.map(fn, list) or R.map(fn)(list)
Compose with:
R.pipe(f, g, h)(data) // left → right These tutorials use [email protected]. Helpers span Math, List, Function, Object, Logic, Relation, and Type—ideal for point-free pipelines in React, Redux, and Node services.
Why Use Ramda?
You can write the same transforms with loops or Lodash. Ramda packages them as pure, composable functions that never touch your originals.
| Need | How Ramda helps |
|---|---|
| Reusable transforms | Curry once: const doubleAll = R.map(n => n * 2) |
| Readable pipelines | R.pipe runs steps left to right |
| Safe updates | R.assoc / R.map return new data |
| Clear predicates | R.propEq(true, "active") names the rule |
How a Ramda Call Runs
Think “build the tool, then pass the data”:
| Step | What happens |
|---|---|
| 1. Load | npm install ramda or a CDN script exposes R |
| 2. Configure | Supply transforms first: R.map(fn) or R.filter(pred) |
| 3. Pass data | List or object is the final argument (or end of a pipe) |
| 4. Get new value | Original input is unchanged; use the returned result |
Your First Ramda Utility
Install via npm, or load from a CDN and double a list with R.map:
npm install ramda <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ramda R.map demo</title>
</head>
<body>
<h1>Ramda.js R.map()</h1>
<p>Doubled list:</p>
<pre id="out"></pre>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ramda.min.js"></script>
<script>
function double(n) {
return n * 2;
}
var result = R.map(double, [1, 2, 3]);
document.getElementById("out").textContent = JSON.stringify(result);
</script>
</body>
</html> Node.js import
const R = require('ramda');
const process = R.pipe(
R.filter(n => n > 2),
R.map(n => n * 2),
R.sum
);
console.log(process([1, 2, 3, 4])); // → 14 How It Works
1. Load. The CDN (or require) exposes the R object.
2. Transform first. R.map(double, list) applies double to each item.
3. Immutable. You get a new array; [1, 2, 3] is unchanged.
Next, explore numeric helpers in Ramda Math.
Ramda vs Lodash
Both help with data—different design goals:
| Ramda | Lodash | |
|---|---|---|
| Style | FP-first, data-last | Utility-first, often data-first |
| Currying | Every function auto-curried | Optional / manual |
| Mutation | Never mutates inputs | Mostly immutable; some mutate |
| Pipelines | R.pipe / R.compose | _.flow / _.chain |
| Map | R.map(fn, list) | _.map(list, fn) |
When to use which
| Use Ramda when… | Prefer Lodash when… |
|---|---|
You want point-free R.pipe pipelines | You want familiar _.map(list, fn) ergonomics |
| Immutability is a hard requirement | You need a larger grab-bag of everyday helpers |
| Your team leans functional | The codebase already depends on Lodash |
Core Building Blocks
These ideas show up in almost every Ramda script:
| Concept | What it does | Example |
|---|---|---|
| Currying | Partial apply, then pass data | R.map(fn) → waits for list |
| Data-last | Config first, data final | R.filter(pred, list) |
R.__ | Placeholder for a middle arg | R.subtract(10, R.__) |
R.pipe | Left-to-right composition | R.pipe(f, g, h)(x) |
| Immutability | Always return new values | R.assoc("k", v, obj) |
Where Is Ramda Used?
Ramda fits FP-friendly JavaScript apps:
| Use case | Why Ramda fits |
|---|---|
| React / Redux state | R.assocPath and R.evolve without mutation |
| API data shaping | Pipe R.pluck, R.groupBy, and R.map |
| Named transforms | Define once, compose with R.pipe, pass data last |
| Validation rules | R.allPass, R.anyPass, R.propSatisfies |
| Node services | Pure helpers that are easy to test |
| Teaching FP | Clear currying and composition patterns |
Key Takeaways
- Ramda is FP-first: curried, data-last, immutable.
- Pattern:
R.map(fn, list)orR.pipe(...)(data). - Prefer
R.pipefor left-to-right readability. - Not Lodash: argument order is different—data comes last.
One line: Ramda turns data work into pure pipelines—next, try Math methods.
Frequently Asked Questions
Did you know?
Ramda is automatically curried, data-last, and immutable—pass data last, get new values back, and compose with R.pipe and R.compose. These tutorials use [email protected].
Next: Ramda Math
Practice the first category of helpers—numbers and arithmetic.
8 people found this page helpful
