Allow `for` piping
Closed this issue · 11 comments
Basically just this :
for a
1
|> c
(maybe allowing this ? =>)
for a in b
1
.c
The former works on master.
As for the latter, that would mean allowing every possible construction to be dot-accessible. We might invoke some more ambiguities in some situations:
f ->
a
.p
# `f(->).p` or `f((->).p)` ?
Not sure how that's an ambiguity since it has been a specialcase since coffee. I wasn't thinking about this behavior, but more imitating Ruby's end...
one. Not sure that's as interesting as for piping tho.
if foo
bar
else
baz
.bat
being the same as
(do ->
if foo
bar
else
baz
)bat
This particular specialcase (.
after block closing implicit call) has been justified because -> ...
etc can't directly be dot-accessed.
Not sure that's as interesting as for piping tho.
It's technically possible but probably YAGNI.
Thought so. Having the former is enough for me, but some cases are interesting.
I'd love to be able to do
bar =
* \abc
* \def
.join ' '
That's exactly the can of worms I'm afraid to open; it's not immediately clear what's going on.
Following your if
examples, it would parse as:
(bar =
\abc
\def
).join ' '
but the intention is probably:
bar = [
\abc
\def
].join ' '
I understand your concerns, and I know you're right, as usual.
That said, it's certainly convenient to be able to:
bound = ->
...
.bind foo
zs = for x of xs
...
.concat ys
rather than:
bound = (->
...
)bind foo
zs = do
for x of xs
...
.concat ys
It should be safe to make literal functions and "KEYWORD Expression? Block" constructions chainable.
For the second part, yes. For the first part, maybe I'd say no for consistency, as we saw before
Discluding function literals:
- doesn't satisfy the
.bind
use case. - is also incosistent, because of named
function
s.
Lemme rephrase: make things that require Block chainable.
That's interesting. Does that mean dropping the OUTDENT DOT
specialcase in addImplicitParentheses
? 'Cause I think that's the most common use case.
Does that mean dropping the
OUTDENT DOT
specialcase
Nope. Being able to chain from implicit calls is far more important.