Haskell: Turtle: get return value from shell

How do you extract value from Shell monad?

I would like to streamline the list of ร  la bash commands &&, but I would also like to extract the final value ExitCode.

Let's 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 figure out if I could implement this using Control.Foldl, but could not find a solution.

Any ideas?

More generally, why Turtle does not provide a function with such a signature:

sh' :: MonadIO io => Shell a -> io a 
+4
source share
2 answers

Turtle.Shell fold :: MonadIO io => Shell a -> Fold a b -> io b Control.Foldl Fold, : last :: Fold a (Maybe a). , ExitCode, :

import Control.Monad.IO.Class
import Turtle.Shell  as TS
import Control.Foldl as CF

sh' :: MonadIO io => Shell a -> io (Maybe a)
sh' c = TS.fold c CF.last
+4

sh' :: MonadIO io => Shell a -> io a , Shell a [a] ( select :: [a] -> Shell a), .

+2

Source: https://habr.com/ru/post/1684570/


All Articles