Ramda.js R.sequence() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.sequence(of, list) turns a list of wrapped values into one wrapped list. A “wrapper” is anything that holds values in a special way: an array (many possible values), a Maybe (a value or nothing), or a function (a value that depends on input) (official Ramda docs).

Stable since v0.19.0: R.sequence is not deprecated, experimental, or non-standard. Note: since v0.29, R.of takes a type first — write R.of(Array), not R.of.

Syntax

Call R.sequence. Start with this line.

Ramda
R.sequence(of, list) or R.sequence(of)(list)
CallWhat it does
R.sequence(of, list) or R.sequence(of)(list)Primary signature.
R.sequence(...)Call the list helper.

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

Library declarations
Ramda
R.sequence(of, list) or R.sequence(of)(list)

Parameters

ParameterDescription
ofRequired. Wraps a plain value; a function or a type with an of method
traversableOptional. A list of wrapped values; omit it to get a reusable function

Return Value

Return ValueDescription
*One wrapper that holds the list of inner values

Ramda Examples

Example 1 — Every Combination of Options

Each inner array is a set of choices; the result lists every way to pick one from each.

Ramda
const options = [['S', 'M'], ['red', 'blue']];

console.log(R.sequence(R.of(Array), options));
// [['S', 'red'], ['S', 'blue'], ['M', 'red'], ['M', 'blue']]
Try It Yourself

How It Works

  1. Wrapper. R.of(Array) tells Ramda the wrapper is an array.
  2. Choices. There are 2 sizes and 2 colors.
  3. Pick one of each. Every size is paired with every color.
  4. Result. 2 × 2 = 4 outfits. For exactly two lists, R.xprod gives the same pairs.

Example 2 — All or Nothing with One-Item Arrays

Use [value] for “present” and [] for “missing”.

Ramda
console.log(R.sequence(R.of(Array), [[1], [2], [3]]));  // [[1, 2, 3]]
console.log(R.sequence(R.of(Array), [[1], [], [3]]));   // []
Try It Yourself

How It Works

  1. One choice each. [1], [2], [3] each offer a single value.
  2. One combination. 1 × 1 × 1 = 1, so the result is [[1, 2, 3]].
  3. A missing value. [] offers zero choices, and 1 × 0 × 1 = 0.
  4. Nothing. The result is an empty array: one missing value cancels everything.

Example 3 — Validate Every Input at Once

Parse each string into [number] or [], then sequence to get all numbers or none.

Ramda
const parse = (s) => (s.trim() !== '' && !isNaN(Number(s)) ? [Number(s)] : []);
const parseAll = (inputs) => R.sequence(R.of(Array), R.map(parse, inputs));

console.log(parseAll(['1', '2', '3']));  // [[1, 2, 3]]
console.log(parseAll(['1', 'x', '3']));  // []
Try It Yourself

How It Works

  1. Parse. parse('2') gives [2]; parse('x') gives [].
  2. Map. R.map(parse) turns the inputs into a list of one-item or empty arrays.
  3. Sequence. All valid → [[1, 2, 3]]; one invalid → [].
  4. Shortcut. R.traverse(R.of(Array), parse, inputs) does the map and sequence in one call.

Example 4 — Official: The Maybe Pattern

The docs use a Maybe type. Here is a tiny one, so the official samples run without a library.

Ramda
const Nothing = { map: () => Nothing, ap: () => Nothing, toString: () => 'Nothing' };
const Just = (x) => ({
  map: (f) => Just(f(x)),
  ap: (m) => m.map(x),
  toString: () => 'Just(' + JSON.stringify(x) + ')'
});
const Maybe = { of: Just };

console.log(String(R.sequence(Maybe, [Just(1), Just(2), Just(3)])));  // Just([1,2,3])
console.log(String(R.sequence(Maybe, [Just(1), Just(2), Nothing])));  // Nothing
Try It Yourself

How It Works

  1. Maybe. Just(x) holds a value; Nothing holds none. Both have map and ap, which Ramda calls.
  2. Start. Ramda calls Maybe.of([]), giving Just([]), then adds each value from the right.
  3. All Just. Every value is present, so the list fills up: Just([1,2,3]).
  4. Any Nothing. Nothing.ap always returns Nothing, so the whole result is Nothing.

Example 5 — Run Several Functions on One Input

A list of functions becomes one function that returns a list of results.

Ramda
const stats = R.sequence(R.always, [R.inc, R.dec, R.negate]);

console.log(stats(5));  // [6, 4, -5]
console.log(R.juxt([R.inc, R.dec, R.negate])(5));  // [6, 4, -5]
Try It Yourself

How It Works

  1. Wrapper. For functions, R.always is the of: it wraps a value in a function that ignores its input.
  2. Combine. R.sequence joins the three functions into one, stats.
  3. Call. stats(5) feeds 5 to each function: 6, 4, -5.
  4. Simpler option. R.juxt does exactly this and reads more clearly in everyday code.

Browser & Runtime Support

R.sequence() is plain JavaScript inside Ramda 0.19.0+. The R.of(Array) form shown here needs Ramda 0.29+; passing Array.of as the first argument also works in older versions.

✓ Ramda 0.19.0+ · Any JS runtime

Ramda.js R.sequence()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun. Custom wrapper types only need map and ap methods (or the fantasy-land/* versions).

100% With Ramda loaded
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.sequence() Universal

Bottom line: Safe in any project with Ramda (check with npm ls ramda). If you upgrade from a version before 0.29, update every R.of passed to R.sequence. These labs load [email protected].

Frequently Asked Questions

R.sequence(of, list) takes a list of wrapped values and returns one wrapped list. For example, a list of Maybes becomes a Maybe of a list: all Just values give Just([...]), and any Nothing gives Nothing. With arrays, it returns every combination that picks one item from each inner array.
It tells Ramda how to wrap a plain value: a function such as R.of(Array) or Array.of, or a type with an of method such as Maybe. Ramda uses it to build the starting value, for example [[]] for arrays.
Arrays represent several possible values. sequence picks one value from each inner array in every possible way, so 2 choices times 2 choices gives 4 combinations: [[1, 3], [1, 4], [2, 3], [2, 4]].
R.traverse(of, fn, list) maps fn over the list and then sequences the result in one step. R.sequence(of, list) is the same as R.traverse(of, R.identity, list): the items are already wrapped, so no mapping is needed.
No. Promises do not provide the map and ap methods Ramda needs, so R.sequence throws a TypeError. Use Promise.all to turn a list of Promises into a Promise of a list.
No. R.sequence has been a stable Ramda list function since v0.19.0. Since v0.29, R.of takes a type first, so write R.of(Array) instead of passing R.of on its own.

Next: R.slice()

Copy a range of items from a list or string.

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