-
Notifications
You must be signed in to change notification settings - Fork 107
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
Partial expressions #186
Comments
Very nice! While I this might not be my preferred choice, having more alternatives explored is indeed a good thing. The babel plugin is also nice to have! I does have some bugs tho ( |
This is something I have been exploring for a few years in |
IMHO, this is the biggest downside of the ones that were listed. F# flavour of the pipeline operator can await promises but it is a bit verbose. I wonder how things would have looked like if there was a pipline operator specific for promises and null/undefined values. promise >>= map(_ * 2) >>= filter(_ > 10);
[1,2,3] |> _[10] >>= _ + 10; |
@ducaale , F# has suggestions for await postfix, like Yeah, some kind of custom syntax would be amazing! I think, @Jopie64 suggested something similar in #167 (comment) . doubtful and off-topic imho on await and pipesWith that said, imho the importance of
In this context, Still, it'd be cool if we could achieve that too! |
Closing this issue, as the proposal has advanced to stage 2 with Hack-style syntax. |
To prove minimal style extensibility (#167) and explore our options in Hack vs minimal argument, I created a babel plugin to support an experimental syntax of partial expressions. It could cover most of Hack style use cases, while allowing F# style and being useful on its own.
This syntax turns an expression with one missing argument into a function with a single argument. For example:
NOTE: The plugin uses
_
as a placeholder for a value, because it's hard to override syntax in babel. In reality, it could be#
,?
or something else.tl;dr: you can try the syntax in the babel playground.
With minimal style pipes
I tried to cover two special cases for pipes:
When the partial expression is in the subject of piping:
And when it's in a pipe:
.
Similarly, we could do partial application:
And as a context:
Rules
Expression is considered partial if an unbound _ symbol is used in it.
Expression boudaries are limited by following:
2.1 root of an expression
2.2 body of a function
2.3 pipe in pipeline operator
What are the downsides?
await _
syntax in pipesWe can add implicit indication of partial expression borders to solve first three issues. Though I'm not sure if the syntax will still be beneficial, compared to simple arrow functions.
Why not partial application?
Partial application seem to be solving a very narrow issue, while if we extend that idea to partial expressions — we could cover much more use cases, and it's especially sweet in the context of pipes.
Why not just Hack style?
Compared to Hack style, partial expressions:
Previous work
@trustedtomato made a proposal for partial expressions in 2018, probably with similar intentions, though it seems to be stalled.
UPD: @citycide has been exploring a similar syntax for a few years in the param.macro (also can be used as a babel plugin)
Because the idea is quite simple, I suspect there were more discussions / experiments with it.
Links
Play with it in the babel playground
And here's the plugin repository
Thanks 🙂
The text was updated successfully, but these errors were encountered: