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)
Call
What 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
Parameter
Description
pred
Required. Function. Stop predicate. When it returns truthy on the current value, that value is returned and the loop ends.
fn
Required. Function. Iterator. Called on the current value while pred is falsy. Must return the next value (same type as init).
init
Required. Any. Starting value. The loop checks pred(init) first; if falsy, fn(init) runs and the cycle repeats.
Return Value
Return Value
Description
a
The 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.
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
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.
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
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.
Compatibility
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 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.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.