Skip to content

Map ok - #106

Open
misterfish wants to merge 3 commits into
gkz:masterfrom
misterfish:map-ok
Open

Map ok#106
misterfish wants to merge 3 commits into
gkz:masterfrom
misterfish:map-ok

Conversation

@misterfish

@misterfish misterfish commented May 8, 2016

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Comment thread src/List.ls
[f x for x in xs]

map-ok = (f, xs) -->
[res for x in xs when (res = f x)?]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, [that for xs when (f ..)?]

@pepkin88 pepkin88 Oct 21, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for x in xs is consistent with other functions, but otherwise [that for xs | f(..)?] 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants