33

Does Ramda have a function to remove false values from a list?

I know we can simply do var compact = R.filter(R.identity); but am I missing the ready-made function?

Dema
  • 6,867
  • 11
  • 40
  • 48

2 Answers2

63

There's no direct equivalent, but R.filter(R.identity) and R.filter(Boolean) both work.

R.reject(R.isNil) is useful for filtering out null/undefined.

davidchambers
  • 23,918
  • 16
  • 76
  • 105
8

You can use Ramda Adjunct's compact which works like the Underscore / Lodash equivalents.

RA.compact([0, 1, false, 2, '', 3]); //=> [1, 2, 3]
Undistraction
  • 42,754
  • 56
  • 195
  • 331