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]
Author by
Dema
Updated on July 14, 2022Comments
-
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 over 4 yearsSadly this doesn't appear to be available as of 10/20/19
-
Undistraction over 4 years
-
MobileVet over 4 yearsWhoops... Didn't see the 'Adjunct' call out. My bad, thanks!