Ramda.js R.invoker() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

A factory that turns a method name into a curried function with the target object last. Instead of str.slice(6), you get a reusable sliceFrom(6, str). Part of Ramda Function since v0.1.0 (stable — not deprecated, experimental, or non-standard).

Why data-last? You can fill in the method arguments now and pass the data later — perfect for R.map and R.pipe.

Syntax

Call R.invoker. Start with this line.

Ramda
R.invoker(arity, method)
CallWhat it does
R.invoker(arity, method)Primary signature.
R.invoker(...)Call the function helper.

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

Library declarations
Ramda
R.invoker(arity, method)

Parameters

ParameterDescription
arityRequired. Number of method arguments (not counting the target)
methodRequired. Method name as a string

Return Value

Return ValueDescription
*Curried function of arity + 1 arguments

Ramda Examples

Example 1 — Official One-Argument Method

Turn slice into a function that takes the start index, then the string.

Ramda
const sliceFrom = R.invoker(1, "slice");

console.log(sliceFrom(6, "abcdefghijklm"));
// → "ghijklm"

console.log(sliceFrom(6)("abcdefghijklm"));
// → "ghijklm"
Try It Yourself

How It Works

  1. Arity 1. slice gets one argument here (the start), so the result waits for 1 + 1 = 2 arguments.
  2. Target last. 6 goes to slice; the string is the object it runs on.
  3. Same call. It runs "abcdefghijklm".slice(6) → "ghijklm".
  4. Curried. sliceFrom(6)("…") gives the same answer, one argument at a time.

Example 2 — Two Arguments and Partial Application

Pre-fill the method arguments to build a ready-to-use helper.

Ramda
const sliceFrom6 = R.invoker(2, "slice")(6);
console.log(sliceFrom6(8, "abcdefghijklm"));
// → "gh"

const firstSection = R.invoker(2, "slice")(0, 4);
console.log(firstSection("4242 4242 4242 4242"));
// → "4242"
Try It Yourself

How It Works

  1. Arity 2. slice(start, end) takes two arguments, so 3 are needed in total.
  2. One pre-filled. sliceFrom6 holds 6; (8, str) completes it → str.slice(6, 8) → "gh".
  3. Both pre-filled. firstSection holds 0, 4 and only waits for the string → "4242".
  4. Docs note. Writing R.invoker(2, "slice", 0, 4) does not pre-fill — those extra values are ignored.

Example 3 — Zero-Argument Method in R.map

Because the target comes last, an invoker drops straight into R.map.

Ramda
const shout = R.invoker(0, "toUpperCase");

console.log(shout("ada"));
// → "ADA"

console.log(R.map(shout, ["ada", "lin"]));
// → ["ADA", "LIN"]
Try It Yourself

How It Works

  1. Arity 0. toUpperCase() takes no arguments, so shout waits only for the target.
  2. Direct call. shout("ada") runs "ada".toUpperCase() → "ADA".
  3. In map. R.map passes each string as the target → ["ADA", "LIN"].
  4. Tip. For this exact job Ramda also has R.toUpper; invoker shines for methods Ramda doesn’t wrap.

Example 4 — Your Own Object Methods

Invoker calls the method on the target, so this works as expected.

Ramda
const greet = R.invoker(1, "greet");

const user = {
  name: "Ada",
  greet(greeting) {
    return greeting + ", " + this.name + "!";
  }
};

console.log(greet("Hello", user));
// → "Hello, Ada!"

console.log(greet("Hi")(user));
// → "Hi, Ada!"
Try It Yourself

How It Works

  1. Name only. greet knows the method name, not the object — any object with a greet method works.
  2. Target last. "Hello" is the method argument; user is the target.
  3. this is the target. Ramda calls user.greet("Hello"), so this.name is "Ada".
  4. Curried. greet("Hi") is a reusable “say Hi” function waiting for a user.

Example 5 — Missing Method Throws

If the target has no such method, Ramda throws a clear TypeError.

Ramda
const shout = R.invoker(0, "toUpperCase");

try {
  shout(42);
} catch (err) {
  console.log(err.name);
  console.log(err.message);
}
// → TypeError
// → 42 does not have a method named "toUpperCase"
Try It Yourself

How It Works

  1. Check first. Before calling, Ramda checks that the target isn’t null / undefined and that target[method] is a function.
  2. Numbers fail. 42 has no toUpperCase, so the check fails.
  3. Clear message. The error names both the target and the method.
  4. Handle it. Use try/catch or R.tryCatch when input types can vary.

Browser & Runtime Support

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

✓ Stable · Ramda 0.1.0+

R.invoker()

Invoker itself needs nothing special, but the method you name must exist in that runtime — e.g. R.invoker(1, "at") needs an ES2022 engine.

100% With Ramda 0.1.0+
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.invoker Ramda 0.1.0+

Bottom line: Safe for production once Ramda is loaded. Check support for the method you invoke, not for invoker. The labs on this page use [email protected].

Frequently Asked Questions

R.invoker(arity, method) returns a curried function. It collects arity method arguments, then the target object last, and calls target[method](...args). The docs sample is R.invoker(1, 'slice')(6, 'abcdefghijklm') //=> 'ghijklm'.
Arity is how many arguments the method itself takes — the target object is not counted. R.invoker(1, 'slice') waits for 2 arguments in total: one for slice, then the target. Its length is arity + 1.
No. R.invoker only reads arity and method; extra arguments are ignored. R.invoker(2, 'slice', 0, 4) still waits for its arguments. Partially apply the result instead: R.invoker(2, 'slice')(0, 4).
Ramda throws a TypeError such as: 42 does not have a method named "toUpperCase". It also throws when the target is null or undefined.
Prefer Ramda's own helpers (R.toUpper, R.trim, R.split, R.slice) when they exist. Use R.invoker for your own class or object methods, or built-in methods Ramda does not wrap, when you want a curried, data-last function.
No. R.invoker has been part of Ramda since v0.1.0 and is stable — not deprecated, experimental, or non-standard.

Next: R.juxt()

Learn how to run a list of functions on the same arguments and collect every result.

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