5 ms·
Though I program in languages that most follow the obj.method(args) pattern, I really prefer the args |> function |> function pattern and I wish it was the norm
by g5becks 6y ago
Though I program in languages that most follow the obj.method(args) pattern, I really prefer the args |> function |> function pattern and I wish it was the norm in every programming language.
- dahfizz 6y agoIn what language is that used? It reminds me of pipes in bash. I can see it being useful in circumstances where you have lots of function calls and fewer arguments (just like pipes), but I think it would look really ugly and hard to parse with a long arg list.
- paublyrne 6y agoElixir for one. Yes it works best when you have one argument to pass, as the first argument is passed implicitly. https://hexdocs.pm/elixir/Kernel.html#%7C%3E/2 https://hexdocs.pm/elixir/Kernel.html#%7C%3E/2
- jdmichal 6y agoIt's a common functional thing. I know F# has both `|>` and `<|` to go both directions. It also has `||>` and `|||>` variants which take two- or three-value tuples and spread them to arguments. https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/functions/#function-composition-and-pipelining https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...
- phaedryx 6y agoSee also Clojure's threading macros: https://clojure.org/guides/threading_macros https://clojure.org/guides/threading_macros
- Certhas 6y agoJulia supports it, too: https://docs.julialang.org/en/v1/base/base/#Base.:|%3E https://docs.julialang.org/en/v1/base/base/#Base.:|%3E
- int_19h 6y agoThese are two different use cases. In the first case, which method the call actually dispatches to depends on obj, so it kinda makes sense for it to be syntactically distinct from other args. The pipeline syntax is normally used with free-standing functions that are statically dispatched. Now, yes, there are languages with multimethods, where the distinction is less obvious. For those that always dispatch on all arguments, a uniform syntax makes more sense. CLOS is a good example.