Ramda.js R.promap() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

R.promap(f, g, h) wraps a function h with a pre-processor f for its input and a post-processor g for its output, so promap(f, g, h)(x) === g(h(f(x))) (official Ramda docs).

Stable since v0.28.0: R.promap is not deprecated, experimental, or non-standard. Older Ramda versions don’t include it.

Syntax

Call R.promap. Start with this line.

Ramda
R.promap(pre, post, fn)
CallWhat it does
R.promap(pre, post, fn)Primary signature.
R.promap(...)Call the function helper.

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

Library declarations
Ramda
R.promap(pre, post, fn)

Parameters

ParameterDescription
fRequired. Pre-processor: changes the input
gRequired. Post-processor: changes the output
hRequired. The core function being wrapped

Return Value

Return ValueDescription
*The value returned by R.promap().

Ramda Examples

Example 1 — Official decodeString

Two promap layers: one decodes a letter, the other applies it to a whole word. This is the sample from the Ramda docs.

Ramda
const decodeChar = R.promap((s) => s.charCodeAt(), String.fromCharCode, R.add(-8));
const decodeString = R.promap(R.split(''), R.join(''), R.map(decodeChar));

console.log(decodeString('ziuli')); // "ramda"
Try It Yourself

How It Works

  1. decodeChar. charCodeAt turns a letter into a number, R.add(-8) shifts it, and String.fromCharCode turns it back.
  2. Pre. R.split('') turns 'ziuli' into ['z', 'i', 'u', 'l', 'i'].
  3. Core. R.map(decodeChar) decodes each letter → ['r', 'a', 'm', 'd', 'a'].
  4. Post. R.join('') glues them back → 'ramda'.

Example 2 — Text In, Text Out

Reuse a number function on string input, and get a string back.

Ramda
const doubleText = R.promap(Number, String, R.multiply(2));

console.log(doubleText('21'));        // "42"
console.log(typeof doubleText('21')); // "string"
Try It Yourself

How It Works

  1. Pre. Number('21') → 21.
  2. Core. R.multiply(2) → 42.
  3. Post. String(42) → '42'.
  4. Result. R.multiply stays a pure number function; only the edges changed.

Example 3 — The Same Result as R.pipe

promap(f, g, h) runs in the order f, h, g — exactly like pipe(f, h, g).

Ramda
const shout = R.promap(R.trim, R.concat(R.__, '!'), R.toUpper);
const shoutPipe = R.pipe(R.trim, R.toUpper, R.concat(R.__, '!'));

console.log(shout('  hi '));     // "HI!"
console.log(shoutPipe('  hi ')); // "HI!"
Try It Yourself

How It Works

  1. Pre. R.trim → 'hi'.
  2. Core. R.toUpper → 'HI'.
  3. Post. R.concat(R.__, '!') adds '!' at the end → 'HI!'.
  4. Order. R.pipe lists the steps in run order; promap lists pre, post, then core.

Example 4 — Adapt an Input Shape

Use an object-based function with array input, and label the result.

Ramda
const area = ({ w, h }) => w * h;

const areaFromPair = R.promap(
  R.zipObj(['w', 'h']),
  (n) => n + ' sq m',
  area
);

console.log(areaFromPair([3, 4])); // "12 sq m"
Try It Yourself

How It Works

  1. Pre. R.zipObj(['w', 'h']) turns [3, 4] into { w: 3, h: 4 }.
  2. Core. area computes 3 * 4 → 12.
  3. Post. n + ' sq m' → '12 sq m'.
  4. Why. area did not change, yet it now accepts a different input format.

Example 5 — One Wrapper for Many Functions

Leave out h to get a reusable adapter, then plug in different core functions.

Ramda
const cleanAndShout = R.promap(R.trim, R.toUpper);

const reverseText = cleanAndShout(R.reverse);
const firstTwo = cleanAndShout(R.take(2));

console.log(reverseText('  abc '));  // "CBA"
console.log(firstTwo('  hello '));   // "HE"
Try It Yourself

How It Works

  1. Curried. R.promap(R.trim, R.toUpper) waits for the core function.
  2. reverseText. Trim → 'abc', R.reverse → 'cba', upper-case → 'CBA'.
  3. firstTwo. Trim → 'hello', R.take(2) → 'he', upper-case → 'HE'.
  4. Payoff. The same pre/post pair wraps any string function.

Browser & Runtime Support

R.promap() is plain JavaScript inside Ramda 0.28.0+. No special browser API is needed.

✓ Ramda 0.28.0+ · Any JS runtime

Ramda.js R.promap()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge, and in Node.js, Deno, and Bun.

100% With Ramda 0.28+ 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.promap() Universal

Bottom line: Safe in any project with Ramda 0.28.0 or later (check with npm ls ramda). Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected].

Frequently Asked Questions

R.promap(f, g, h) wraps the function h: f prepares the input before h runs, and g changes the output after. The result is a new function where promap(f, g, h)(x) === g(h(f(x))).
const decodeChar = R.promap(s => s.charCodeAt(), String.fromCharCode, R.add(-8)); const decodeString = R.promap(R.split(''), R.join(''), R.map(decodeChar)); decodeString('ziuli') returns 'ramda'.
They can give the same result: promap(f, g, h) equals pipe(f, h, g). The difference is intent and order. promap puts the core function last and treats f and g as an adapter around it, which is handy when you reuse the same adapter for many functions.
It comes from profunctors in functional programming. A function is a profunctor: you can map over its input (contravariantly) and its output (covariantly) at the same time. R.promap also dispatches to a promap method on FantasyLand profunctor objects.
No. The function returned by R.promap is unary: only the first argument reaches f. Extra arguments are dropped.
No. R.promap was added in Ramda v0.28.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.T()

A tiny helper that always returns true, whatever you pass in.

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