-
Notifications
You must be signed in to change notification settings - Fork 34
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
Pipeline placeholder ^^ or %% or |x>
#1273
Comments
The TC39 pipe proposal actually uses TC39's It's interesting to look at the examples from the proposal. All of them currently can be written using return links
|> Object.keys(.).map(function (rel) {
return '<' + links[rel] + '>; rel="' + rel + '"';
})
|> link + &.join(', ')
|> this.set('Link', .); Now that we have good general support for placeholders, I wonder if we should add a pipeline-specific one, in particular to align with the TC39 pipe proposal as you say. Simple example: data |> f(%) + g(%)
↓↓↓
f(data) + g(data) This example can't be written with I think the only hard part is we need to choose a placeholder syntax. Related, another option we've discussed (also mentioned in the TC39 bikeshedding issue) is data |x> f(x) + g(x)
↓↓↓
f(data) + g(data) where you can put any identifier (e.g. |
I think the last suggestion is really nice - it sidesteps the issue of needing to remember an explicit symbol out of the mix of candidates. $ (or x) could be the suggested placeholder.
Of course this gets away from the TC39 a bit... |
I'm not sure about that paren operator, but I'd definitely like to support standard JS destructuring: [1,2] |[a,b]> a + b // 3
["head","tail","tail"] |[h,...t]> [h,t] // ["head",["tail","tail"]]
[1,2,10] |$> $[0]+$[2] // 11
{a:1,b:2,c:10} |{a,b}> a+b // 3 Admittedly This notation is mentioned in tc39/proposal-pipeline-operator#91 (comment) (more examples here: tc39/proposal-pipeline-operator#91 (comment), tc39/proposal-pipeline-operator#91 (comment)) so it's plausibly being considered for the TC39 proposal. Although there are hundreds of proposals in that issue, so who knows what they will decide. @STRd6 What do you think of this notation? Worth trying? It is a little funny that |
@edemaine if you're excited about trying |
|x>
Hi,
I think it would be a good idea to have the possiblity of aligning Civet more closely to the pipeline operator proposal (hack style).
I think the only thing needed would be a configuration option to change something like:
pp:= & |> (JSON.stringify ., null, 2) |> console.log
to
pp:= & |> (JSON.stringify ^^, null, 2) |> console.log
I also think it's a bit more readable.
Any thoughts welcome :)
The text was updated successfully, but these errors were encountered: