-
Notifications
You must be signed in to change notification settings - Fork 9
?.
required to be one and two tokens
#2
Comments
See also tc39/proposal-pipeline-operator#91. You raise a good point about I don’t even like We’ve been delaying serious bikeshedding of the particular token to the future, since TC39 might decide against Hack pipes in general anyway (see tc39/proposal-pipeline-operator#91 (comment)). However, the Currently the plan is to have the Babel plugin support choosing which token to use as a plugin option, to allow experimentation with different tokens. But if using I plan to keep this issue open until we reach that Babel implementation point. |
Just a suggestion, can't we introduce a keyword, like // Basic Usage
x |> f(it) //--> f(x)
x |> f(y)(it) //--> f(y)(x)
x |> f //--> Syntax Error
// 2+ Arity Usage
x |> f(it,10) //--> f(x,10)
// Async Solution (Note this would not require special casing)
x |> await f(it) //--> await f(x)
x |> await f(it) |> g(it) //--> g(await f(x))
// Other Expressions
f(x) |> it.data //--> f(x).data
f(x) |> it[it.length-1] //--> let temp=f(x), temp[temp.length-1]
f(x) |> { result: it } //--> { result: f(x) }
// Complex example
anArray => anArray
|> pickEveryN(it, 2)
|> it.filter(...)
|> makeQuery(it)
|> await readDB(it, config)
|> extractRemoteUrl(it)
|> await fetch(it)
|> parse(it)
|> console.log(it);
// Optional Chaining
x |> it?.property We could also use Edit: I discovered that I'm not the first to suggest this.
Originally posted by @robbie01 in tc39/proposal-pipeline-operator#91 (comment)
Originally posted by @aloisdg in tc39/proposal-pipeline-operator#91 (comment) |
The only keywords available here are ones that already are reserved. |
But if that keyword in question only applies in the RHS of the Originally posted by @noppa in tc39/proposal-pipeline-operator#91 (comment)
|
It would be a refactoring hazard when moving code inside a pipeline, as it would silently change meaning. Using an existing identifier is a nonstarter. |
But This problem is inherent in using punctuators in the "nullary" position. Javascript just doesn't do that. The closest we get is an empty array or an empty object. And single characters are wont to combine with other characters to form tokens. A two character punctuator might avoid this, if carefully chosen. My earlier suggestion of |
However,
(For what it’s worth, adding a number like |
Now that babel/babel#13191 (for topic token The simplest solution might be to add punctuator tokens More specifically, these productions would also be added:
From the developer’s perspective, Alternatively, a syntactic annotation could be used, rather than adding new punctuator tokens. Something like:
|
The confusion issues with using I'd be fine with (I still lightly prefer |
@tabatkins: As far as I can tell,
I suppose as far as aesthetics go, I’m personally used to Clojure’s But my preference for any particular token is similarly weak. It’s a shame that |
@js-choi Wouldn't this be ambiguous with Tuples? const result = [1] |> #[0]
result === ??? /// 1 or #[0] |
@mAAdhaTTah: Oh, good catch; you are right. From what I recall tuples are undecided between |
In
value |> ?.foo
,?.
is tokenised as a single token (OptionalChainingPunctuator
) so can't be resolved into?
and.
by the grammar.Using a "unary operator" for this case is a possible workaround, but it's not straightforward because
?.foo
matches the extantOptionalChain
production. And you've still got to allow for? . value
or(?).value
. (If it wasn't for this case, you could just add?
toPrimaryExpression
and then disallow it outside a pipeline.)Also
value |> ?.foo?.bar
seems pretty confusing. So, as much as I love?
, it's probably the wrong character. (?%
isn't a legal expression or a token...)Other than that, count me as TeamHack. This proposal achieves left to right function evaluation, which is the main goal. And I think making
value |> foo(?)
look like a function is a gain - the first time you see it, you'll have a good guess at what's going on.The text was updated successfully, but these errors were encountered: