Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using » in place of .map is a trap #960

Closed
AlexDaniel opened this issue Oct 10, 2016 · 1 comment
Closed

Using » in place of .map is a trap #960

AlexDaniel opened this issue Oct 10, 2016 · 1 comment
Labels
docs Documentation issue (primary issue type) trap

Comments

@AlexDaniel
Copy link
Member

AlexDaniel commented Oct 10, 2016

There are actually two cases to cover.

I've seen it several times on #perl6 when people tried to do this when they first learned aout »:

<a b c d.say # Oops!

Well, okay, it works today, but the idea is that the execution order is not defined, so doing ».say is probably not the best idea.

OK, I get it. But still, if I don't care about the execution order, I can use » anywhere I use .map, right?

Oops.

See this:

say (<a b c d>, <x y z>).map: *.elems # (4 3)     ← OK, that's what we want
say (<a b c d>, <x y z>)».elems       # (4 3)      YEAH, it works, great!

# but we may want to use something more
# complex than just a method call. For example this:
say (<a b c d>, <x y z>).map: *.elems × -1     # (-4 -3)
say (<a b c d>, <x y z>)».&(*.elems × -1)      # ((-1 -1 -1 -1) (-1 -1 -1)) – ??? Why?
say (<a b c d>, <x y z>).deepmap: *.elems × -1 # ((-1 -1 -1 -1) (-1 -1 -1)) – OK, so it's like deepmap in this case…

Perhaps see these conversations:

@AlexDaniel AlexDaniel added the docs Documentation issue (primary issue type) label Oct 10, 2016
@AlexDaniel AlexDaniel changed the title Using » in place of .map is a pitfall Using » in place of .map is a trap Jan 2, 2017
@AlexDaniel
Copy link
Member Author

By the way, we have it mentioned in /operators, but a separate section in traps is not going to hurt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type) trap
Projects
None yet
Development

No branches or pull requests

1 participant