Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 843 Bytes

no-chain.md

File metadata and controls

35 lines (26 loc) · 843 Bytes

Forbid the use of _.chain

In lodash/fp, it is not recommended to use _.chain(x) or _(x) to chain commands. Instead, it is recommended to use _.flow/_.compose/_.flowRight.

For more information on why to avoid _.chain, please read this article

Fail

const value = [1, 2, 3];

_(value)
  .filter(x => x > 1)
  .map(x => x * x)
  .value();

_.chain(value)
  .filter(x => x > 1)
  .map(x => x * x)
  .value();

Pass

_.flow(
  _.filter(x => x > 1),
  _.map(x => x * x)
)(value);

_.compose(
  _.map(x => x * x),
  _.filter(x => x > 1)
)(value);