3 ms·
For what it's worth, I often do something like this: (!) = flip ($) Which then allows me to do things like mycommand ! grep "error" ! sort ! uniq ! w
by thinkpad20 12y ago
For what it's worth, I often do something like this:
(!) = flip ($)
Which then allows me to do things like
mycommand ! grep "error" ! sort ! uniq ! wc lineCount
Which is nice because it visually resembles `|` (which is a reserved symbol in Haskell).
Similarly for fmap:
(<!>) = flip (<$>)
result <- get <!> table <!> lookup "foo"
print result ! liftIO
Or for function composition:
(~>) = flip (.)
doStuff = reverse ~> head ~> negate ~> print
doStuff [1,2,3]
That being said, lisp does seem far more suited to shell programming than Haskell, because every function is variadic. What would probably be nice (and probably has been done) is a Lisp with syntax extended to include a few symbols to allow bash commands like |, >, etc:
$ def nth-line (n) (read a | head -(n) | tail -n 1)
$ ssh -i .ssh/some.pem (python show_servers.py | grep 'cool server' | cut -d ' '
-f 3 | nth-line 1)