gkz / prelude-ls

prelude.ls is a functionally oriented utility library - powerful and flexible, almost all of functions are curried. It is written in, and is the recommended base library for, http://livescript.net
http://preludels.com/
MIT License
424 stars 59 forks source link

Map ok #106

Open misterfish opened 8 years ago

misterfish commented 8 years ago

Hi,

My proposal is a map-ok function, which is identical to map, except that returning undefined or null will remove the element from the output list.

The use case is that I often find myself wanting to remove an element while I'm mapping, and end up using an extra compact. It would be nice to be able to do it the first time around. (cf. Perl, for example, where you can return ()).

pepkin88 commented 7 years ago

You say you end up using an extra compact, although it strips all falsy values, not just voids and nulls. And I actually more often find myself wanting all falsy values out, than just all nully values.

PS. that works as a value of expressions in the when clauses too.