Python should have Haskell's $ operator
In Python, I often want to repeatedly say "apply some function to the remainder of the current statement". Think foo(bar(baz(qux, quux)))
. In my text editor, which mostly automatically handles the parenthesis correctly, this is a quick thing to type.
Haskell's $
operator is pretty sweet. All of the following are equivalent in Haskell:
putStrLn (show (1 + 1)) putStrLn (show $ 1 + 1) putStrLn $ show (1 + 1) putStrLn $ show $ 1 + 1
Python should adopt Haskell's $
operator. That is, the following should be equivalent:
foo(bar(baz(qux, quux))) foo $ bar $ baz(qux, quux) foo $ bar $ baz $ qux, quuxThough odd looking, there's easy consistency for unary functions:
foo() foo $Haters of the new-ish print might find respite in
print $ foo
.
No comments:
Post a Comment