Lodash _.flowRight() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Util utilities

What You’ll Learn

By the end of this tutorial, you’ll chain small functions into one pipeline with Lodash’s _.flowRight(), running steps right to left—the same direction as mathematical compose.

01

Core Syntax

_.flowRight(f, g, h) or an array of functions.

02

Right to Left

The rightmost function runs first on your input.

03

Compose Notation

flowRight(f, g, h)(x) equals f(g(h(x))).

04

First Step Args

Only the rightmost function gets all call arguments.

05

Pure Pipelines

Build testable transforms without side effects.

06

vs flow

Know when direction reverses.

What Is _.flowRight()?

_.flowRight() is Lodash’s right-to-left function composition helper. You supply two or more functions; Lodash returns a new function that runs the rightmost function first, then pipes each result to the function on its left. It matches how mathematicians write compose: outer function on the left, inner on the right.

💡
Beginner tip — read from the right

_.flowRight(addFive, double, square)(3) means: start with 3, run square first, then double, then addFive. It equals addFive(double(square(3))).

If you already use a manual compose(f, g) helper, _.flowRight(f, g) does the same thing with Lodash’s variadic or array syntax—no custom utility required.

📝 Syntax

Pass functions as variadic arguments or inside one array:

javascript
_.flowRight([funcs])

// or

_.flowRight(funcs)

Syntax Rules

  • funcs — one or more functions, or a single array of functions.
  • Order — right to left: the last listed function runs first.
  • Return value — a new composed function you call later.
  • First execution — all arguments go to the rightmost function only.
  • Earlier steps — each receives one value (return from the step to its right).
javascript
import flowRight from "lodash/flowRight";



const addFive = (x) => x + 5;

const double = (x) => x * 2;

const square = (x) => x * x;



const composed = flowRight(addFive, double, square);



composed(3);

// square(3) -> 9, double(9) -> 18, addFive(18) -> 23

⚡ Quick Reference

TaskCode patternEquivalent
Compose three fns_.flowRight(f, g, h)f(g(h(x)))
Array form_.flowRight([f, g, h])Same as variadic
Two-step compose_.flowRight(f, g)(x)f(g(x))
Reverse direction_.flow(f, g, h)h(g(f(x)))
With partial_.flowRight(g, _.partial(f, 2))Fix inner args
Identity end_.flowRight(f, _.identity)Pass-through last
Direction
R → L

Last fn runs first

Returns
Function

Composed pipeline

Opposite
flow

Left to right

Category
Util

Composition

🧰 Parameters

How arguments work in a _.flowRight() pipeline:

funcs Required

Functions to compose, passed individually or as one array. At least one function is required for a meaningful pipeline.

_.flowRight(format, parse, fetch)
rightmost function Multi-arg OK

Receives every argument from the outer call: composed(a, b) invokes the last function as last(a, b).

_.flowRight(double, add)(3, 4)
earlier functions Unary

Each step to the left gets one value—the return of the function on its right. Binary ops break unless you curry or partial first.

_.flowRight(f, g, h)(x)
return value Function

The composed function’s return value is whatever the leftmost function returns.

const run = _.flowRight(steps)

For multi-argument math on two numbers, keep both operands in the rightmost step or use _.partial() before composing.

Examples Gallery

Practical _.flowRight() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Trace a numeric pipeline from right to left.

Example 1 — Numeric pipeline

Square, double, then add five—composed right to left.

javascript
const addFive = (x) => x + 5;

const double = (x) => x * 2;

const square = (x) => x * x;



const composed = _.flowRight(addFive, double, square);



console.log(composed(3));

// square(3)=9, double(9)=18, addFive(18)=23
Try It Yourself

How It Works

composed(3) expands to addFive(double(square(3))). List functions with the innermost transform on the right—the opposite order from _.flow().

Example 2 — Classic two-function compose

Multiply first, then add—matches a hand-written compose(add, multiply).

javascript
const add = (x) => x + 5;

const multiply = (x) => x * 2;



const compose = (f, g) => (x) => f(g(x));



const viaFlowRight = _.flowRight(add, multiply);

const viaCompose = compose(add, multiply);



console.log(viaFlowRight(10)); // add(multiply(10)) = 25

console.log(viaCompose(10));   // 25
Try It Yourself

How It Works

With add, multiply, and input 10, the rightmost step runs first: multiply(10) = 20, then add(20) = 25. The old tutorial incorrectly claimed this pattern outputs 15.

📈 Practical Patterns

String transforms, nested equivalents, and direction comparison.

Example 3 — String slug pipeline

Remove spaces first, then lowercase, then trim—listed right to left so the slug step runs on raw input.

javascript
const trim = (str) => str.trim();

const toLower = (str) => str.toLowerCase();

const removeSpaces = (str) => str.replace(/\s+/g, "");



// Order in call: outer steps on the left, inner on the right

const toSlug = _.flowRight(trim, toLower, removeSpaces);



const input = "   Hello World   ";

console.log(toSlug(input)); // "helloworld"

How It Works

The same three string functions produce the same final slug with _.flow(trim, toLower, removeSpaces)—only the order in the argument list changes. Pick the direction that matches how you read the pipeline.

Example 4 — Equivalent nested calls

See how flowRight desugars into nested function calls.

javascript
const f = (x) => x + 2;

const g = (x) => x * 3;

const h = (x) => x - 1;



const composed = _.flowRight(f, g, h);

const nested = (x) => f(g(h(x)));



console.log(composed(4));  // f(g(h(4))) = f(9) = 11

console.log(nested(4));    // 11

How It Works

_.flowRight(f, g, h)(x) always equals f(g(h(x))) for unary functions. The rightmost name in the list is the innermost call.

🚀 Beyond the Basics

Compare direction with flow and keep steps pure.

Example 5 — flowRight vs flow

Same three functions, opposite evaluation order.

javascript
const f = (x) => x + 1;

const g = (x) => x * 2;

const h = (x) => x - 1;



console.log(_.flowRight(f, g, h)(5));

// h(5)=4, g(4)=8, f(8)=9  — right to left



console.log(_.flow(f, g, h)(5));

// f(5)=6, g(6)=12, h(12)=11 — left to right
Try It Yourself

When to prefer flowRight

Use _.flowRight() when you think in compose notation (inner function last in the list). Use _.flow() when you read transforms in data order (first step leftmost).

Example 6 — Pure unary transforms

Small arithmetic steps with no shared state—easy to test in isolation.

javascript
const inc = (x) => x + 1;

const double = (x) => x * 2;

const dec = (x) => x - 3;



const transform = _.flowRight(dec, double, inc);



console.log(transform(5));

// inc(5)=6, double(6)=12, dec(12)=9

How It Works

Pure functions compose predictably. Debug by testing the rightmost step first, then work leftward through the list.

🧠 How _.flowRight() Works

1

Collect functions

Lodash flattens variadic args or uses the array you pass in.

Setup
2

Return composed fn

The new function closes over the ordered list of steps.

Factory
3

Run right to left

On call, invoke the rightmost fn with all args, then pipe each return to the fn on its left.

Execute
=

Final return value

Whatever the leftmost function returns becomes the pipeline result.

📝 Notes

  • Only the rightmost function receives multiple arguments from composed(a, b).
  • Steps to the left should be unary—one input, one output.
  • Order matters: _.flowRight(f, g) is not the same as _.flowRight(g, f).
  • _.flowRight() composes return-value functions—not Express (req, res, next) middleware.
  • Handle errors in individual steps; flowRight does not add try/catch between steps.
  • Previous in the series: _.flow() for left-to-right composition.

Conclusion

_.flowRight() turns a list of small functions into one reusable pipeline that runs right to left—matching mathematical compose and manual f(g(x)) patterns.

Keep steps unary after the first execution, verify order with nested-call equivalents, and switch to _.flow() when data-order left-to-right reads more naturally.

💡 Best Practices

✅ Do

  • Write one responsibility per function (parse, filter, format)
  • List inner transforms on the right, outer on the left
  • Test the rightmost step first, then the full compose
  • Use array form when building the list dynamically
  • Pair with _.partial when the inner step needs fixed args

❌ Don’t

  • Chain binary math ops to the left without currying
  • Assume flowRight works like Express middleware arrays
  • Hide side effects inside steps without documenting them
  • Swap order casually—results change completely
  • Build huge pipelines when a plain function reads clearer

Key Takeaways

Knowledge Unlocked

Five things to remember about _.flowRight()

Use these points when composing function pipelines.

5
Core concepts
🔀 02

Compose

f(g(h(x))) form.

Mechanics
📝 03

Unary steps

After first run.

Pitfall
📈 04

Pure fns

Test each step.

Practical
05

flow

Reverse direction.

Compare

❓ Frequently Asked Questions

_.flowRight() takes one or more functions and returns a new composed function. When you call it, the rightmost function runs first with your arguments; each earlier function receives the return value of the function to its right. Execution order is right to left—like mathematical compose.
Pass them as separate arguments (_.flowRight(f, g, h)) or as one array (_.flowRight([f, g, h])). Both forms work in Lodash 4.
Only the rightmost function (the one that runs first) receives all arguments from the outer call. Every earlier function receives a single value—the previous step's return value. Design steps after the first execution as unary functions.
_.flowRight() composes right to left: flowRight(f, g, h)(x) equals f(g(h(x))). _.flow() composes left to right: flow(f, g, h)(x) equals h(g(f(x))). Same functions, opposite order.
No. Express middleware chains use (req, res, next) signatures and side effects. _.flowRight() composes value-returning functions—better for pure transforms than HTTP middleware wiring.
Use it when you think in compose notation—the innermost transform runs first—or when your team reads function lists from the result backward to the input. It pairs naturally with manual compose helpers and functional programming patterns.
Did you know?

_.flowRight(f, g, h)(x) is the same as f(g(h(x))) for unary functions—the rightmost function in the list is the innermost call. Lodash also ships _.flow() for the opposite direction, which matches reading a data pipeline top to bottom.

Practice _.flowRight() in the Live Editor

Open the Try It editor, run the examples, and build your own right-to-left pipelines.

Open Try It editor →

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