Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ramda.js

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?

like image 284
Dema Avatar asked Apr 27 '15 15:04

Dema


2 Answers

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.

like image 54
davidchambers Avatar answered Oct 06 '22 08:10

davidchambers


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

RA.compact([0, 1, false, 2, '', 3]); //=> [1, 2, 3]
like image 36
Undistraction Avatar answered Oct 06 '22 10:10

Undistraction