How do you extract a value out of the Shell monad?
I would like to sequence a list of commands à la bash's &&
, but I would also like to extract the final ExitCode
value.
Say I have the following code:
import Turtle
type Commands = [Shell ExitCode]
run :: (MonadIO io) => Commands -> io ExitCode
run cs = whatIsThisFunction $ Prelude.foldl (.&&.) (return ExitSuccess) cs
whatIsThisFunction :: (MonadIO io) => Shell a -> io a
whatIsThisFunction = undefined
I tried to see if I could implement this with Control.Foldl, but did not find a solution.
Any ideas?
More generally, why doesn't Turtle provide a function with such signature:
sh' :: MonadIO io => Shell a -> io a
Turtle.Shell
provides you with afold :: MonadIO io => Shell a -> Fold a b -> io b
andControl.Foldl
gives you a bunch ofFold
s amongst which:last :: Fold a (Maybe a)
. You can combine the two to extract the lastExitCode
your command returns like so: