3 ms·
It seems that pipeline-style programming is now popular in many modern programming languages, for example C# (with Linq), F# (with the |> pipe operator and the
by ot 16y ago
It seems that pipeline-style programming is now popular in many modern programming languages, for example C# (with Linq), F# (with the |> pipe operator and the Seq module), and Ruby and JS+jQuery (with method chaining).
I really wish Python had some syntactic feature that encourages this style, doing "gen_cat(gen_open(gen_find(...)))" is rather cumbersome, compared to "gen_find(...) | gen_open | gen_cat".
Of course you can override __or__ like some libraries do, but it is not the One Way To Do It...
- xtacy 16y agoMathematica has a nice syntax for function application, mapping over lists, etc. It's also possible to define such operators in Haskell, which has the added advantage of type-safety. f @ {1,2,3} == f[{1,2,3}] f /@ list == map(f, list) f @@ {1,2,3} == f[1,2,3] (#1 * 2) /@ {1,2,3} == {2,4,6} etc.
- ot 16y agoThat's like F# operator |> f |> g == g(f) [1 .. 3] |> Seq.map (fun x -> x * x) |> Seq.sum |> printfn "%A" // prints 14
- Tyr42 16y agoI like Haskell's function composition syntax: . (f . g)(x) = f(g(x)) cat.open.find ...
- lloeki 16y agoSomeone took an interesting stab at it: http://stackoverflow.com/questions/2281693/is-it-a-good-idea-to-have-a-syntax-sugar-to-function-composition-in-python http://stackoverflow.com/questions/2281693/is-it-a-good-idea... Sadly this is one of the reasons I still write shell scripts: pipes are so explicit and compact. Python seems to gather more of a practical functional crowd these times around.