I'm personally someone who advocates for languages to keep their feature set small and shoot to achieve a finished feature set quickly. However. I would be lying if I didn't secretly wish that all languages adopted the `|>` syntax from Elixir. ``` params |> Map.get("user") |> create_user() |> notify_admin() ```
It would be even better without the `>`, though. The `|>` is a bit awkward to type, and more noisy visually.
Pipelining might be my favorite programming language feature
101–110 of 360 posts
Re: Pipelining might be my favorite programming language feature
#102C# has had "Pipelining" (aka Linq) for 17 years. I do miss this kind of stuff in Go a little.
I don't see how LINQ provides an especially illuminating example of what is effectively method chaining. It is an exemplar of expressions [0] more than anything else, which have little to do with the idea of passing results from one method to another. [0]: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
In this case I would say extension methods are what he's really referring to, of which Linq to objects is built on top of.
Re: Pipelining might be my favorite programming language feature
#103Earlier quoted context omitted.
Consistency is more important. If you ever wrote: a(b()) then you're already breaking your left-to-right/first-to-last rule.
There are some math books out there that use (x)f. My understanding is (some) algebraists tried to make it a thing ~60 years ago but it never really caught on.
Re: Pipelining might be my favorite programming language feature
#104I'm personally someone who advocates for languages to keep their feature set small and shoot to achieve a finished feature set quickly. However. I would be lying if I didn't secretly wish that all languages adopted the `|>` syntax from Elixir. ``` params |> Map.get("user") |> create_user() |> notify_admin() ```
Yes, a small feature set is important, and adding the functional-style pipe to languages that already have chaining with the dot seems to clutter up the design space. However, dot-chaining has the severe limitation that you can only pass to the first or "this" argument. Is there any language with a single feature that gives the best of both worlds?
```
params
|> Map.get("user")
|> create_user()
|> (¬ify_admin("signup", &1)).() ```
or
```
params
|> Map.get("user")
|> create_user()
|> (fn user -> notify_admin("signup", user) end).() ```
Re: Pipelining might be my favorite programming language feature
#105I feel like, at least in some cases, the article is going out of its way to make the "undesired" look worse than it needs to be. Compairing fn get_ids(data: Vec ) -> Vec { collect(map(filter(map(iter(data), |w| w.toWingding()), |w| w.alive), |w| w.id)) } to fn get_ids(data: Vec ) -> Vec { data.iter() .map(|w| w.toWingding()) .filter(|w| w.alive) .map(|w| w.id) .collect() } The first one would read more easily (and, s…
See how adding line breaks still keeps the `|w| w.alive` very far from the `filter` call? And the `|w| w.id` very far from the `map` call?
If you don't have the pipeline operator, please at least format it something like this:
fn get_ids(data: Vec) -> Vec {
collect(
map(
filter(
map(
iter(data),
|w| w.toWingding()
),
|w| w.alive
),
|w| w.id
)
)
}
...which is still absolutely atrocious both to write and to read!Also see how this still reads fine despite being one line:
fn get_ids(data: Vec) -> Vec {
data.iter().map(|w| w.toWingding()).filter(|w| w.alive).map(|w| w.id).collect()
}
It's not about line breaks, it's about the order of applying the operations, and about the parameters to the operations you're performing.Re: Pipelining might be my favorite programming language feature
#106Earlier quoted context omitted.
I feel like Haskell really missed a trick by having $ not go the other way, though it's trivial to make your own symbol that goes the other way.
Haskell has & which goes the other way: users & map validate & catMaybes & mapM persist
In my programming language, I added `.>` as a reverse-compose operator, so pipelines of function compositions can also be read uniformly left-to-right, e.g.
process = map validate .> catMaybes .> mapM persistRe: Pipelining might be my favorite programming language feature
#107Earlier quoted context omitted.
It would be even better without the `>`, though. The `|>` is a bit awkward to type, and more noisy visually.
I disagree, because then it can be very ambiguous with an existing `|` operator. The language has to be able to tell that this is a pipeline and not doing a bitwise or operation on the output of multiple functions.
Re: Pipelining might be my favorite programming language feature
#108Re: Pipelining might be my favorite programming language feature
#109This is just super basic functional programming. Seems like we're taking the long way around...
Re: Pipelining might be my favorite programming language feature
#110This is far different than the pattern described in the article, though. Small shame they have come to have the same name. I can see how both work with the metaphor; such that I can't really complain. The "pass a single parameter" along is far less attractive to me, though.