Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 780 Bytes

prefer-compact.md

File metadata and controls

60 lines (42 loc) · 780 Bytes

Prefer _.compact over _.filter with identity function

When using _.filter to remove all falsy values, it can be more concise to use _.compact instead.

Rule Details

This rule takes no arguments.

Fail

_.map(f, a);

_.flatten(_.map(f, a));

_.flow(
  _.map(f1),
  _.flatten,
  f2
)

_.compose(
  f2,
  _.flatten,
  _.map(f1)
)

Pass

_.compact(f, a);

_.map(f, a);

_.flatten(a);

_.flow(
  _.compact(f1),
  f2
)

_.compose(
  f2,
  _.compact(f1)
)

_.flow(
  _.map(f1),
  f2,
  _.flatten
)

When Not To Use It

If you do not want to enforce using _.compact, and prefer _.map and _.flatten instead, you should not use this rule.