Ramda.js R.applySpec() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Turns a spec object of functions into one function that builds a matching object — each property (including nested ones) is filled by calling its function with the same arguments. Part of Ramda Function since v0.20.0 (stable — not deprecated).

Note: The spec is recursive: nested objects of functions become nested result objects. See also R.juxt and R.converge.

Syntax

Call R.applySpec. Start with this line.

Ramda
R.applySpec(spec)(...args)
CallWhat it does
R.applySpec(spec)(...args)Primary signature.
R.applySpec(...)Call the function helper.

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

Library declarations
Ramda
R.applySpec(spec)(...args)

Parameters

ParameterDescription
specRequired. Object mapping keys to functions (recursively)

Return Value

Return ValueDescription
*A function that returns an object shaped like spec

Ramda Examples

Example 1 — Official getMetrics

Build a nested metrics object from two numbers.

Ramda
const getMetrics = R.applySpec({
  sum: R.add,
  nested: { mul: R.multiply }
});

getMetrics(2, 4);
// → { sum: 6, nested: { mul: 8 } }
Try It Yourself

How It Works

  1. Spec. Top-level sum and nested mul are both functions.
  2. Call. getMetrics(2, 4) feeds 2 and 4 to every leaf.
  3. Sum. R.add(2, 4) → 6.
  4. Nested. R.multiply(2, 4) → 8, kept under nested.mul.

Example 2 — Pick Fields from One Record

Pass one object; each prop helper reads a field into a smaller shape.

Ramda
const summarize = R.applySpec({
  name: R.prop("name"),
  age: R.prop("age")
});

summarize({ name: "Ada", age: 36, city: "London" });
// → { name: "Ada", age: 36 }
Try It Yourself

How It Works

  1. One argument. The person object is passed to every leaf function.
  2. name. R.prop("name") reads "Ada".
  3. age. R.prop("age") reads 36.
  4. city dropped. Only keys in the spec appear in the result.

Example 3 — Nested Stats

Compute total plus a nested product and difference.

Ramda
const pack = R.applySpec({
  total: R.add,
  stats: {
    product: R.multiply,
    difference: R.subtract
  }
});

pack(10, 3);
// → { total: 13, stats: { product: 30, difference: 7 } }
Try It Yourself

How It Works

  1. Shared inputs. Both 10 and 3 reach every leaf.
  2. total. R.add(10, 3) → 13.
  3. stats.product. R.multiply(10, 3) → 30.
  4. stats.difference. R.subtract(10, 3) → 7 (first minus second).

Example 4 — R.applySpec vs R.juxt

Same math, labeled object vs ordered array.

Ramda
R.juxt([R.add, R.multiply])(2, 4);
// → [6, 8]

R.applySpec({ sum: R.add, mul: R.multiply })(2, 4);
// → { sum: 6, mul: 8 }
Try It Yourself

How It Works

  1. juxt. Returns results in array order: [6, 8].
  2. applySpec. Returns the same values under named keys.
  3. Choose juxt when position is enough.
  4. Choose applySpec when you want a clear object shape (and nesting).

Example 5 — Line Total

Keep quantity and price, and compute their product in one object.

Ramda
const line = R.applySpec({
  qty: (q, p) => q,
  price: (q, p) => p,
  total: R.multiply
});

line(3, 12);
// → { qty: 3, price: 12, total: 36 }
Try It Yourself

How It Works

  1. Pass-through keys. qty and price return each argument.
  2. Derived key. R.multiply(3, 12) → 36.
  3. One call. Inputs and computed fields share the same invocation.
  4. Pattern. Useful for DTOs, API payloads, and report rows.

Browser & Runtime Support

R.applySpec is a Ramda Function helper since v0.20.0. It runs anywhere Ramda runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.20.0+

R.applySpec()

Available in full Ramda builds from v0.20.0 onward. Works in evergreen browsers and current Node LTS when Ramda is loaded.

100% With Ramda 0.20+
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.applySpec Ramda 0.20.0+

Bottom line: Safe for production once Ramda is loaded. Ideal for DTOs, metrics objects, and nested report shapes. Official reference: ramdajs.com/docs/#applySpec.

Frequently Asked Questions

R.applySpec(spec) returns a function. That function calls every function in spec with the same arguments and builds a new object with the same keys (and nested shape). Official: getMetrics(2, 4) → { sum: 6, nested: { mul: 8 } }.
const getMetrics = R.applySpec({ sum: R.add, nested: { mul: R.multiply } }); getMetrics(2, 4); //=> { sum: 6, nested: { mul: 8 } }. Added in v0.20.0. See also R.converge and R.juxt.
Yes. The spec is recursive. A nested object of functions becomes a nested object of results. That is why nested.mul is 8 in the official sample, not a top-level mul key.
R.juxt([R.add, R.multiply])(2, 4) returns an array [6, 8]. R.applySpec({ sum: R.add, mul: R.multiply })(2, 4) returns a named object { sum: 6, mul: 8 }. Same inputs, labeled vs ordered output.
R.evolve transforms properties that already exist on an object. R.applySpec builds a new object from arguments (or from one value you pass in). Evolve needs a source object of the same shape; applySpec needs a recipe of functions.
No. R.applySpec is a stable Ramda Function helper from v0.20.0. It is not deprecated, experimental, or non-standard.

Next: R.applyTo()

Pass a value into a function — the thrush combinator, useful for point-free pipelines.

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

11 people found this page helpful