What's Ramda equivalent to underscore.js 'compact'?

12,451

Solution 1

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.

Solution 2

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

RA.compact([0, 1, false, 2, '', 3]); //=> [1, 2, 3]
Share:
12,451
Dema
Author by

Dema

Updated on July 14, 2022

Comments

  • Dema
    Dema almost 2 years

    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?

  • MobileVet
    MobileVet over 4 years
    Sadly this doesn't appear to be available as of 10/20/19
  • Undistraction
    Undistraction over 4 years
  • MobileVet
    MobileVet over 4 years
    Whoops... Didn't see the 'Adjunct' call out. My bad, thanks!