Ramda.js R.until() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Logic

Definition

Ramda’s R.until() answers an iterative question: keep applying a transform until a stop test passes on the current value. You pass a predicate, an iterator function, and an initial value. Native JavaScript might write a while (!pred(val)) { val = fn(val); } loop. until names that pattern, curries it, and returns the final value when pred becomes truthy.

The official sample doubles a number until it exceeds 100. Starting from 1, the chain is 1→2→4→8→16→32→64→128, then gt(100)(128) is true and 128 is returned. Need a single conditional transform instead of a loop? That is R.unless or R.when. Need every intermediate step as a list instead of the final value? That is R.unfold in the List category. Previous Logic helper is R.unless. Next is R.when for pass-only conditional transforms.

Syntax

Call R.until. Start with this line.

Ramda
R.until(pred, fn, init)
CallWhat it does
R.until(pred, fn, init)Primary signature.
R.until(...)Call the logic helper.

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

Library declarations
Ramda
R.until(pred, fn, init)

Parameters

ParameterDescription
predRequired. Function. Stop predicate. When it returns truthy on the current value, that value is returned and the loop ends.
fnRequired. Function. Iterator. Called on the current value while pred is falsy. Must return the next value (same type as init).
initRequired. Any. Starting value. The loop checks pred(init) first; if falsy, fn(init) runs and the cycle repeats.

Return Value

Return ValueDescription
aThe first value where pred(value) is truthy. Same type as init and fn's output.

Ramda Examples

📚 Getting Started

The official Ramda double-until-over-100 sample, then the same idea compared with a manual while loop.

Example 1 — Official Double Until Over 100

Double repeatedly until the value exceeds 100. Starting from 1 yields 128.

Ramda
R.until(R.gt(R.__, 100), R.multiply(2))(1);
//=> 128

// Steps: 1 → 2 → 4 → 8 → 16 → 32 → 64 → 128
// Stops when gt(100)(128) is true
Try It Yourself

How It Works

R.gt(R.__, 100) is the stop predicate. While the value is not greater than 100, R.multiply(2) doubles it. At 128, the predicate is truthy and 128 is returned. That is the docs sample from ramdajs.com.

Example 2 — vs Manual while Loop

Same result as a hand-written loop. until is declarative and curried.

Ramda
const pred = R.gt(R.__, 100);
const fn = R.multiply(2);

const untilManual = (p, f, init) => {
  let val = init;
  while (!p(val)) { val = f(val); }
  return val;
};

R.until(pred, fn)(1);
//=> 128

untilManual(pred, fn, 1);
//=> 128
Try It Yourself

How It Works

Both versions check the predicate, apply the iterator while falsy, and return when truthy. until packages that pattern as a curried Ramda helper you can partial-apply before supplying init.

📈 Practical Patterns

Step tracing, curried leftovers, and the infinite-loop pitfall with a safe predicate.

Example 3 — Step Trace: Double Until >= 16

From 1, doubling stops at 16 when R.gte(R.__, 16) is truthy.

Ramda
const pred = R.gte(R.__, 16);
const double = R.multiply(2);

R.until(pred, double)(1);
//=> 16

// Trace: 1 → 2 → 4 → 8 → 16 (pred(16) is true, stop)
Try It Yourself

How It Works

The loop runs while pred is falsy: 1→2→4→8→16. At 16, gte(16)(16) is true, so 16 is returned without another doubling step.

Example 4 — Curried Leftover: grow(0)

Partially apply pred and fn, then call the leftover with an initial value.

Ramda
const grow = R.until(R.gt(R.__, 50), R.add(10));

grow(0);
//=> 60

// Steps: 0 → 10 → 20 → 30 → 40 → 50 → 60
// Stops when gt(50)(60) is true
Try It Yourself

How It Works

grow is a reusable loop. R.add(10) runs while R.gt(R.__, 50) is falsy. At 50 the predicate is still false (50 > 50 is false), so one more add yields 60, where the predicate is true.

Example 5 — Pitfall: Predicate Never True

If pred never becomes truthy, the loop never stops. Always use a stop predicate that can eventually succeed.

Ramda
// UNSAFE — infinite loop (do not run):
// R.until(R.always(false), R.inc)(0);

// SAFE — pred eventually becomes truthy:
const safeGrow = R.until(R.gt(R.__, 50), R.add(10));

safeGrow(0);
//=> 60
Try It Yourself

How It Works

R.always(false) as a stop predicate means fn keeps running forever. In production, ensure pred can become truthy, or combine a growth predicate with an upper-bound guard in pred or fn.

Browser Support

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

✓ Ramda 0.20.0+ · Any JS runtime

Ramda.js R.until()

Load Ramda 0.20.0 or later via CDN or npm, then call R.until with a stop predicate and iterator. No extra browser API is required.

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

Bottom line: Safe in any project that includes Ramda 0.20.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.until(pred, fn, init) takes a stop predicate, an iterator function, and an initial value. While pred(value) is falsy, fn(value) runs. When pred(value) is truthy, that value is returned. Added in v0.20.0. Type: (a → Boolean) → (a → a) → a → a. Arity 3, curried.
R.until(R.gt(R.__, 100), R.multiply(2))(1) returns 128. The value doubles (1→2→4→8→16→32→64→128) until gt(100)(128) is true, then 128 is returned.
unless applies one conditional transform: pass keeps x, miss runs fn once. until is iterative: fn runs repeatedly until pred becomes truthy on the current value. Different problem, different helper.
Yes. If pred never becomes truthy, fn keeps running and the loop never stops. Always use a stop predicate that can eventually succeed, or add an upper bound in fn or pred.
They do the same work: while pred is falsy, apply fn. until names the pattern, curries pred and fn, and returns a reusable leftover you can pass an init value to later.
No. R.until is a stable Ramda logic helper from v0.20.0. It is not deprecated, experimental, or non-standard.

Continue to R.when()

Learn how to transform only when a predicate passes with Ramda R.when().

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