lodash/fp re-exports the same methods as the standard build, converted to be immutable, auto-curried, iteratee-first, and data-last. Use it when you want to build reusable, composable functions instead of one-off imperative calls.
var fp = require('lodash/fp');How lodash/fp differs from the standard build
| Col 1 | Standard (lodash) | Functional (lodash/fp) |
|---|---|---|
| Argument order | Data first: _.map(collection, iteratee) | Iteratee first, data last: fp.map(iteratee, collection) |
| Currying | Not curried | Every method is auto-curried |
| Mutation | Methods such as set, merge, and assign mutate their input | All methods return a new value and leave the input untouched |
Iteration order (forEach, transform) | Not reversed | Iteration and argument order are flipped to fit data-last composition |
Auto-currying
Call an fp method with fewer arguments than it needs, and it returns a function waiting for the rest:
var double = fp.map(function (n) { return n * 2; });
double([1, 2, 3]);
// => [2, 4, 6]var addOne = fp.add(1);
addOne(2);
// => 3Immutability
The standard _.set and merge mutate the object you pass in. Their fp equivalents never do — they return a new value and leave your original data untouched:
var original = { a: { b: 1 } };
var updated = fp.set('a.b', 99, original);
original.a.b;
// => 1 (untouched)
updated.a.b;
// => 99This makes fp methods safe to use with state you don't own, such as values kept in a Redux store or React state.
Composing functions
fp.flow runs a list of functions left to right, passing each function's result to the next — useful for describing a pipeline as data instead of nested calls:
var pipeline = fp.flow(
fp.filter(function (n) { return n % 2 === 0; }),
fp.map(function (n) { return n * 10; })
);
pipeline([1, 2, 3, 4, 5, 6]);
// => [20, 40, 60]fp.flowRight (aliased as fp.compose) runs the same list right to left, matching traditional mathematical function composition.
When to reach for lodash/fp
Prefer the standard build for straightforward, one-off transformations — its data-first order reads naturally and its examples throughout this reference use it directly. Reach for lodash/fp when you're composing reusable pipeline functions ahead of time, passing partially applied functions as callbacks, or need a guarantee that a Lodash call will never mutate a value you pass in.
Next steps
- Compare this to Lodash's other data-first, mutation-aware methods in the API reference.
- See Installation for other ways to load the
fpbuild, including per-method imports underlodash/fp/*.