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.
Fundamentals
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.
Foundation
📝 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).
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"
📤 Console output:
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
📤 Console output:
11
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
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
📤 Console output:
9
How It Works
Pure functions compose predictably. Debug by testing the rightmost step first, then work leftward through the list.
Compare
📋 _.flowRight vs related patterns
Topic
_.flowRight
_.flow
Manual compose
_.chain
Direction
Right → left
Left → right
You choose
Method chain
Equivalent
f(g(h(x)))
h(g(f(x)))
Custom helper
Lodash wrapper
Best for
Compose notation
Data pipelines
One-off libs
Lodash methods on data
Purity
Small pure fns
Same
Same
May mutate (tap)
Express middleware
Not equivalent
Not equivalent
N/A
N/A
🧠 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.
Important
📝 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).
Handle errors in individual steps; flowRight does not add try/catch between steps.
Previous in the series: _.flow() for left-to-right composition.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.flowRight()
Use these points when composing function pipelines.
5
Core concepts
←01
R → L
Last fn runs first.
Basics
🔀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.