Re:Using Python generators for real work [pdf]
by xtacy on Sunday January 23, 2011 @06:29PM
(#2133650)
Mathematica 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.That's like F# operator |>
f |> g == g(f)
[1 .. 3] |> Seq.map (fun x -> x * x) |> Seq.sum |> printfn "%A" // prints 14
Re:Using Python generators for real work [pdf]
by lloeki on Monday January 24, 2011 @12:52PM
(#2135921)
Someone took an interesting stab at it:
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.
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...