-
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
Backwards pipe operator? #3
Comments
x => double <| square <| x really doesn't read much easier than x => double(square(x)) Not enough benefit to warrant another new operator. |
I use and enjoy the Elm version. |
Also, semi-related: have you considered a composition operator as well? const squareThenDouble = square >> double
const squareThenDouble = double << square |
Although shoot, I guess those are already taken in JavaScript, haha :D https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators |
@acdlite What about Haskell style for composition? const squareThenDouble = double . square |
@roman01la That does't work as it obviously collides with the property access operator. You could use Haskell const squareThenDouble = double <<< square |
@bergus You are right. My main concern for const squareThenDouble = double $ square |
@roman01la |
@bergus @roman01la I agree that the Having used the pipeline operator in Elixir quite a bit, and as it has no backward pipe, the symbol is just not great. I wish I could suggest a great alternative, but even |
Ultimately the utility of forward pipe is declarative data flow. Because JS isn't curried, its functions are rarely composable, negating compositional operators. Backpipe is particularly tricky, because F# ( |
I like it, it would add the ability to 'decorate' functions which is not covered by the decorator spec
|
I am using the bitwise operators << and >> to achieve both forward and backward piping for now. https://github.com/michaelmitchell/babel-plugin-pipe-composition |
@bergus The comparison provided should be const foo = double <| square versus const foo = x => double(square(x)) To illustrate this, suppose we have const add = a => b => b + a
const mul = a => b => b * a
const div = a => b => b / a instead of writing this const f2c = x => div(9)(mul(5)(add(-32)(x))) We could just write const f2c = div(9) <| mul(5) <| add(-32) In chaining together data processing const f2c = add(-32) |> mul(5) |> div(9) Whereas when dealing with embedded components (common on the web, i.e. HTML), const updateSiteCart = template <| page <| cart <template>
<page>
<cart />
</page>
</template> |
i think we should keep the es-pipeline-operator proposal as minimal as possible, just provide a small concept that everyone can agree on, so that we have the biggest change of passing all the way down to stage-4, otherwise there is way to much potential for discussions |
It makes sense to include both directions. Many people who are into functional programming prefer right-to-left operators, like However, there will inevitably be people who prefer the left-to-right/sequential style. So, there's no real reason to exclude either option, in my opinion. It would take almost no effort to include both I think it's too restrictive to force only left-to-right style with only |
@babakness I might be mistaken, but I think you're comparison is off: const foo = x => double <| square <| x Regardless of its usefulness, introducing a const foo = x => foo <| x |> bar
// vs
const foo = x => foo(x |> bar);
// or (depending on associativity of `<|` and `|>`)
const foo = x => foo(x) |> bar I don't deny the usefulness of such an operator, but adding the |
@TiddoLangerak I don't think it really complicates much. It's a directional binary operator. It's as simple as flipping the order of arguments of the underlying function. These are literally called Precedence would determine which happens first where both directions are used simultaneously... and precedence needs to be defined anyway. |
@TiddoLangerak Interesting, thanks for clarifying. |
The backwards pipe operator may be pursued in a follow-on proposal. The scope of this proposal will be limited to |
How about a backwards pipe operator as well?
The text was updated successfully, but these errors were encountered: