Replies: 12 comments
-
That is an ugly operator, and completely contrary to everything else in V. Not sure why is is called a "pipe operator" either, since it is used for chaining multiple functions. V already supports "chaining" function calls, by simply doing println('hello, world'.capitalize().trim_right('ld')+'k!') prints "Hello, work!" |
Beta Was this translation helpful? Give feedback.
-
What makes it "contrary to everything else in V"? Why would something so useful in the context of UNIX pipes, Haskell, F#, OCaml, Elixir, Elm, JavaScript/TypeScript, Julia, Hack, and others not be useful in V? |
Beta Was this translation helpful? Give feedback.
-
The operator itself is unlike anything else in V. Yes, Unix pipes are useful, but they will likely be done a different way. |
Beta Was this translation helpful? Give feedback.
-
No, it only supports method calls. I think this was closed too soon without discussion, so I'm reopening it. |
Beta Was this translation helpful? Give feedback.
-
@fritzblue it would help if you gave a motivating example in V of using this feature. |
Beta Was this translation helpful? Give feedback.
-
Method-call order for function calls (a.k.a JS Whichever syntax you use, the result of calling Currently you may say that we just add methods instead. This is not flexible for users because:
|
Beta Was this translation helpful? Give feedback.
-
I do not agree that |
Beta Was this translation helpful? Give feedback.
-
In the TC39
They use arrow functions instead: |
Beta Was this translation helpful? Give feedback.
-
For calling generic functions on a container which can be of any type, not just arrays: // Method call order with -> operator
container->filter(fn(e){e > 7})->map(fn(e){e * 2})->array()
// Existing function calls
array(map(filter(container, fn(e){e > 7}), fn(e){e * 2})) The map and filter functions work with any container and use lazy evaluation, returning an iterator that produces each element only when needed. So an array function iterates the final iterator in the chain to produce an array. |
Beta Was this translation helpful? Give feedback.
-
I would also like to voice support for this feature. My reason for supporting this is that it makes the code read a lot better. The rescript (different language) docs for their pipe operator contains a good explanation of why this could be useful. https://rescript-lang.org/docs/manual/latest/pipe
The reason I'm referring to rescript is because their implementation allows the piped functions to accept the argument at any location using a placeholder. So if you want the output of a function to be piped as the second argument of another function, that would be possible. For example:
Here, the output of If this is implemented, it doesn't really matter what symbol is used for piping. It could be Aside: If there are three things I could add in Go, it would be sum types, generics and pipe support. Out of those, V already has sum types and generics. Having pipe support would make it a no brainer (for me) to start using V once it stabilizes. |
Beta Was this translation helpful? Give feedback.
-
I'd like to add that |
Beta Was this translation helpful? Give feedback.
-
Too many languages realize the need for a pipe operator after already existing for a while. It would be amazing if V adopted this pattern earlier rather than later.
The ECMAScript proposal currently in flight provides a good introduction to how this feature operates and why it is so helpful. The short pitch is that it gives much greater readability when chaining multiple function calls together (rather than, for example, deeply nesting the function calls).
Beta Was this translation helpful? Give feedback.
All reactions