{- |
   Module     : Development.Shake.Plus.Core
   License    : MIT
   Stability  : experimental

Core definitions of shake-plus.
-}
module Development.Shake.Plus.Core (
  MonadAction(..)
, MonadRules(..)
, UnliftAction(..)
, MonadUnliftAction(..)
, withUnliftAction
, askUnliftAction
, toAction
, RAction
, ShakePlus
, runRAction
, runShakePlus
, parallel
, forP
, par
, Development.Shake.Action
, Development.Shake.Rules
, Development.Shake.FilePattern
, Development.Shake.RuleResult
, Development.Shake.ShakeValue
, Development.Shake.shake
, Development.Shake.shakeArgs
, Development.Shake.shakeOptions
, Development.Shake.ShakeOptions(..)
) where

import           Control.Exception
import           Development.Shake (Action, FilePattern, Rules)
import qualified Development.Shake
import           RIO

-- | Monads in which `Action`s may be embedded.
class MonadIO m => MonadAction m where
  liftAction :: Action a -> m a

instance MonadAction Action where
  liftAction :: Action a -> Action a
liftAction = Action a -> Action a
forall a. a -> a
id

instance MonadAction m => MonadAction (ReaderT r m) where
  liftAction :: Action a -> ReaderT r m a
liftAction = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (Action a -> m a) -> Action a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Action a -> m a
forall (m :: * -> *) a. MonadAction m => Action a -> m a
liftAction

newtype UnliftAction m = UnliftAction { UnliftAction m -> forall a. m a -> Action a
unliftAction :: forall a. m a -> Action a }

-- | Monads which allow their actions to be run in 'Action'.
--
-- For the same reasons as `MonadUnliftIO` this is limited to 'ReaderT'
-- and `IdentityT` transformers on top of `Action'.
class MonadAction m => MonadUnliftAction m where
  {-# INLINE withRunInAction #-}
  withRunInAction :: ((forall a. m a -> Action a) -> Action b) -> m b
  withRunInAction (forall a. m a -> Action a) -> Action b
inner = m (UnliftAction m)
forall (m :: * -> *). MonadUnliftAction m => m (UnliftAction m)
askUnliftAction m (UnliftAction m) -> (UnliftAction m -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \UnliftAction m
u -> Action b -> m b
forall (m :: * -> *) a. MonadAction m => Action a -> m a
liftAction ((forall a. m a -> Action a) -> Action b
inner (UnliftAction m -> forall a. m a -> Action a
forall (m :: * -> *). UnliftAction m -> forall a. m a -> Action a
unliftAction UnliftAction m
u))

instance MonadUnliftAction Action where
  {-# INLINE withRunInAction #-}
  withRunInAction :: ((forall a. Action a -> Action a) -> Action b) -> Action b
withRunInAction (forall a. Action a -> Action a) -> Action b
inner = (forall a. Action a -> Action a) -> Action b
inner forall a. a -> a
forall a. Action a -> Action a
id

instance MonadUnliftAction m => MonadUnliftAction (ReaderT r m) where
  {-# INLINE withRunInAction #-}
  withRunInAction :: ((forall a. ReaderT r m a -> Action a) -> Action b)
-> ReaderT r m b
withRunInAction (forall a. ReaderT r m a -> Action a) -> Action b
inner =
    (r -> m b) -> ReaderT r m b
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((r -> m b) -> ReaderT r m b) -> (r -> m b) -> ReaderT r m b
forall a b. (a -> b) -> a -> b
$ \r
r ->
    ((forall a. m a -> Action a) -> Action b) -> m b
forall (m :: * -> *) b.
MonadUnliftAction m =>
((forall a. m a -> Action a) -> Action b) -> m b
withRunInAction (((forall a. m a -> Action a) -> Action b) -> m b)
-> ((forall a. m a -> Action a) -> Action b) -> m b
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> Action a
run ->
    (forall a. ReaderT r m a -> Action a) -> Action b
inner (m a -> Action a
forall a. m a -> Action a
run (m a -> Action a)
-> (ReaderT r m a -> m a) -> ReaderT r m a -> Action a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ReaderT r m a -> r -> m a) -> r -> ReaderT r m a -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT r m a -> r -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT r
r)

class Monad m => MonadRules m where
  liftRules :: Rules a -> m a

instance MonadRules Rules where
  liftRules :: Rules a -> Rules a
liftRules = Rules a -> Rules a
forall a. a -> a
id

instance MonadRules m => MonadRules (ReaderT r m) where
  liftRules :: Rules a -> ReaderT r m a
liftRules = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (Rules a -> m a) -> Rules a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rules a -> m a
forall (m :: * -> *) a. MonadRules m => Rules a -> m a
liftRules

withUnliftAction :: MonadUnliftAction m => (UnliftAction m -> Action a) -> m a
withUnliftAction :: (UnliftAction m -> Action a) -> m a
withUnliftAction UnliftAction m -> Action a
inner = m (UnliftAction m)
forall (m :: * -> *). MonadUnliftAction m => m (UnliftAction m)
askUnliftAction m (UnliftAction m) -> (UnliftAction m -> m a) -> m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Action a -> m a
forall (m :: * -> *) a. MonadAction m => Action a -> m a
liftAction (Action a -> m a)
-> (UnliftAction m -> Action a) -> UnliftAction m -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnliftAction m -> Action a
inner

askUnliftAction :: MonadUnliftAction m => m (UnliftAction m)
askUnliftAction :: m (UnliftAction m)
askUnliftAction = ((forall a. m a -> Action a) -> Action (UnliftAction m))
-> m (UnliftAction m)
forall (m :: * -> *) b.
MonadUnliftAction m =>
((forall a. m a -> Action a) -> Action b) -> m b
withRunInAction (\forall a. m a -> Action a
run -> UnliftAction m -> Action (UnliftAction m)
forall (m :: * -> *) a. Monad m => a -> m a
return ((forall a. m a -> Action a) -> UnliftAction m
forall (m :: * -> *). (forall a. m a -> Action a) -> UnliftAction m
UnliftAction forall a. m a -> Action a
run))

toAction :: MonadUnliftAction m => m a -> m (Action a)
toAction :: m a -> m (Action a)
toAction m a
m = ((forall a. m a -> Action a) -> Action (Action a)) -> m (Action a)
forall (m :: * -> *) b.
MonadUnliftAction m =>
((forall a. m a -> Action a) -> Action b) -> m b
withRunInAction (((forall a. m a -> Action a) -> Action (Action a))
 -> m (Action a))
-> ((forall a. m a -> Action a) -> Action (Action a))
-> m (Action a)
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> Action a
run -> Action a -> Action (Action a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Action a -> Action (Action a)) -> Action a -> Action (Action a)
forall a b. (a -> b) -> a -> b
$ m a -> Action a
forall a. m a -> Action a
run m a
m

-- | Concrete `Action` runner, hardcoded to `ReaderT r Action a`.
newtype RAction r a = RAction (ReaderT r Action a)
  deriving (a -> RAction r b -> RAction r a
(a -> b) -> RAction r a -> RAction r b
(forall a b. (a -> b) -> RAction r a -> RAction r b)
-> (forall a b. a -> RAction r b -> RAction r a)
-> Functor (RAction r)
forall a b. a -> RAction r b -> RAction r a
forall a b. (a -> b) -> RAction r a -> RAction r b
forall r a b. a -> RAction r b -> RAction r a
forall r a b. (a -> b) -> RAction r a -> RAction r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RAction r b -> RAction r a
$c<$ :: forall r a b. a -> RAction r b -> RAction r a
fmap :: (a -> b) -> RAction r a -> RAction r b
$cfmap :: forall r a b. (a -> b) -> RAction r a -> RAction r b
Functor, Functor (RAction r)
a -> RAction r a
Functor (RAction r)
-> (forall a. a -> RAction r a)
-> (forall a b. RAction r (a -> b) -> RAction r a -> RAction r b)
-> (forall a b c.
    (a -> b -> c) -> RAction r a -> RAction r b -> RAction r c)
-> (forall a b. RAction r a -> RAction r b -> RAction r b)
-> (forall a b. RAction r a -> RAction r b -> RAction r a)
-> Applicative (RAction r)
RAction r a -> RAction r b -> RAction r b
RAction r a -> RAction r b -> RAction r a
RAction r (a -> b) -> RAction r a -> RAction r b
(a -> b -> c) -> RAction r a -> RAction r b -> RAction r c
forall r. Functor (RAction r)
forall a. a -> RAction r a
forall r a. a -> RAction r a
forall a b. RAction r a -> RAction r b -> RAction r a
forall a b. RAction r a -> RAction r b -> RAction r b
forall a b. RAction r (a -> b) -> RAction r a -> RAction r b
forall r a b. RAction r a -> RAction r b -> RAction r a
forall r a b. RAction r a -> RAction r b -> RAction r b
forall r a b. RAction r (a -> b) -> RAction r a -> RAction r b
forall a b c.
(a -> b -> c) -> RAction r a -> RAction r b -> RAction r c
forall r a b c.
(a -> b -> c) -> RAction r a -> RAction r b -> RAction r c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: RAction r a -> RAction r b -> RAction r a
$c<* :: forall r a b. RAction r a -> RAction r b -> RAction r a
*> :: RAction r a -> RAction r b -> RAction r b
$c*> :: forall r a b. RAction r a -> RAction r b -> RAction r b
liftA2 :: (a -> b -> c) -> RAction r a -> RAction r b -> RAction r c
$cliftA2 :: forall r a b c.
(a -> b -> c) -> RAction r a -> RAction r b -> RAction r c
<*> :: RAction r (a -> b) -> RAction r a -> RAction r b
$c<*> :: forall r a b. RAction r (a -> b) -> RAction r a -> RAction r b
pure :: a -> RAction r a
$cpure :: forall r a. a -> RAction r a
$cp1Applicative :: forall r. Functor (RAction r)
Applicative, Applicative (RAction r)
a -> RAction r a
Applicative (RAction r)
-> (forall a b. RAction r a -> (a -> RAction r b) -> RAction r b)
-> (forall a b. RAction r a -> RAction r b -> RAction r b)
-> (forall a. a -> RAction r a)
-> Monad (RAction r)
RAction r a -> (a -> RAction r b) -> RAction r b
RAction r a -> RAction r b -> RAction r b
forall r. Applicative (RAction r)
forall a. a -> RAction r a
forall r a. a -> RAction r a
forall a b. RAction r a -> RAction r b -> RAction r b
forall a b. RAction r a -> (a -> RAction r b) -> RAction r b
forall r a b. RAction r a -> RAction r b -> RAction r b
forall r a b. RAction r a -> (a -> RAction r b) -> RAction r b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> RAction r a
$creturn :: forall r a. a -> RAction r a
>> :: RAction r a -> RAction r b -> RAction r b
$c>> :: forall r a b. RAction r a -> RAction r b -> RAction r b
>>= :: RAction r a -> (a -> RAction r b) -> RAction r b
$c>>= :: forall r a b. RAction r a -> (a -> RAction r b) -> RAction r b
$cp1Monad :: forall r. Applicative (RAction r)
Monad, MonadReader r, Monad (RAction r)
Monad (RAction r)
-> (forall a. IO a -> RAction r a) -> MonadIO (RAction r)
IO a -> RAction r a
forall r. Monad (RAction r)
forall a. IO a -> RAction r a
forall r a. IO a -> RAction r a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> RAction r a
$cliftIO :: forall r a. IO a -> RAction r a
$cp1MonadIO :: forall r. Monad (RAction r)
MonadIO, MonadIO (RAction r)
MonadIO (RAction r)
-> (forall a. Action a -> RAction r a) -> MonadAction (RAction r)
Action a -> RAction r a
forall r. MonadIO (RAction r)
forall a. Action a -> RAction r a
forall r a. Action a -> RAction r a
forall (m :: * -> *).
MonadIO m -> (forall a. Action a -> m a) -> MonadAction m
liftAction :: Action a -> RAction r a
$cliftAction :: forall r a. Action a -> RAction r a
$cp1MonadAction :: forall r. MonadIO (RAction r)
MonadAction, MonadAction (RAction r)
MonadAction (RAction r)
-> (forall b.
    ((forall a. RAction r a -> Action a) -> Action b) -> RAction r b)
-> MonadUnliftAction (RAction r)
((forall a. RAction r a -> Action a) -> Action b) -> RAction r b
forall r. MonadAction (RAction r)
forall b.
((forall a. RAction r a -> Action a) -> Action b) -> RAction r b
forall r b.
((forall a. RAction r a -> Action a) -> Action b) -> RAction r b
forall (m :: * -> *).
MonadAction m
-> (forall b. ((forall a. m a -> Action a) -> Action b) -> m b)
-> MonadUnliftAction m
withRunInAction :: ((forall a. RAction r a -> Action a) -> Action b) -> RAction r b
$cwithRunInAction :: forall r b.
((forall a. RAction r a -> Action a) -> Action b) -> RAction r b
$cp1MonadUnliftAction :: forall r. MonadAction (RAction r)
MonadUnliftAction, Monad (RAction r)
Monad (RAction r)
-> (forall a. String -> RAction r a) -> MonadFail (RAction r)
String -> RAction r a
forall r. Monad (RAction r)
forall a. String -> RAction r a
forall r a. String -> RAction r a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> RAction r a
$cfail :: forall r a. String -> RAction r a
$cp1MonadFail :: forall r. Monad (RAction r)
MonadFail)

-- | Concrete `Rules` collector, hardcoded to `ReaderT r Rules a`.
newtype ShakePlus r a = ShakePlus (ReaderT r Rules a)
  deriving (a -> ShakePlus r b -> ShakePlus r a
(a -> b) -> ShakePlus r a -> ShakePlus r b
(forall a b. (a -> b) -> ShakePlus r a -> ShakePlus r b)
-> (forall a b. a -> ShakePlus r b -> ShakePlus r a)
-> Functor (ShakePlus r)
forall a b. a -> ShakePlus r b -> ShakePlus r a
forall a b. (a -> b) -> ShakePlus r a -> ShakePlus r b
forall r a b. a -> ShakePlus r b -> ShakePlus r a
forall r a b. (a -> b) -> ShakePlus r a -> ShakePlus r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ShakePlus r b -> ShakePlus r a
$c<$ :: forall r a b. a -> ShakePlus r b -> ShakePlus r a
fmap :: (a -> b) -> ShakePlus r a -> ShakePlus r b
$cfmap :: forall r a b. (a -> b) -> ShakePlus r a -> ShakePlus r b
Functor, Functor (ShakePlus r)
a -> ShakePlus r a
Functor (ShakePlus r)
-> (forall a. a -> ShakePlus r a)
-> (forall a b.
    ShakePlus r (a -> b) -> ShakePlus r a -> ShakePlus r b)
-> (forall a b c.
    (a -> b -> c) -> ShakePlus r a -> ShakePlus r b -> ShakePlus r c)
-> (forall a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b)
-> (forall a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r a)
-> Applicative (ShakePlus r)
ShakePlus r a -> ShakePlus r b -> ShakePlus r b
ShakePlus r a -> ShakePlus r b -> ShakePlus r a
ShakePlus r (a -> b) -> ShakePlus r a -> ShakePlus r b
(a -> b -> c) -> ShakePlus r a -> ShakePlus r b -> ShakePlus r c
forall r. Functor (ShakePlus r)
forall a. a -> ShakePlus r a
forall r a. a -> ShakePlus r a
forall a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r a
forall a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b
forall a b. ShakePlus r (a -> b) -> ShakePlus r a -> ShakePlus r b
forall r a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r a
forall r a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b
forall r a b.
ShakePlus r (a -> b) -> ShakePlus r a -> ShakePlus r b
forall a b c.
(a -> b -> c) -> ShakePlus r a -> ShakePlus r b -> ShakePlus r c
forall r a b c.
(a -> b -> c) -> ShakePlus r a -> ShakePlus r b -> ShakePlus r c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: ShakePlus r a -> ShakePlus r b -> ShakePlus r a
$c<* :: forall r a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r a
*> :: ShakePlus r a -> ShakePlus r b -> ShakePlus r b
$c*> :: forall r a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b
liftA2 :: (a -> b -> c) -> ShakePlus r a -> ShakePlus r b -> ShakePlus r c
$cliftA2 :: forall r a b c.
(a -> b -> c) -> ShakePlus r a -> ShakePlus r b -> ShakePlus r c
<*> :: ShakePlus r (a -> b) -> ShakePlus r a -> ShakePlus r b
$c<*> :: forall r a b.
ShakePlus r (a -> b) -> ShakePlus r a -> ShakePlus r b
pure :: a -> ShakePlus r a
$cpure :: forall r a. a -> ShakePlus r a
$cp1Applicative :: forall r. Functor (ShakePlus r)
Applicative, Applicative (ShakePlus r)
a -> ShakePlus r a
Applicative (ShakePlus r)
-> (forall a b.
    ShakePlus r a -> (a -> ShakePlus r b) -> ShakePlus r b)
-> (forall a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b)
-> (forall a. a -> ShakePlus r a)
-> Monad (ShakePlus r)
ShakePlus r a -> (a -> ShakePlus r b) -> ShakePlus r b
ShakePlus r a -> ShakePlus r b -> ShakePlus r b
forall r. Applicative (ShakePlus r)
forall a. a -> ShakePlus r a
forall r a. a -> ShakePlus r a
forall a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b
forall a b. ShakePlus r a -> (a -> ShakePlus r b) -> ShakePlus r b
forall r a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b
forall r a b.
ShakePlus r a -> (a -> ShakePlus r b) -> ShakePlus r b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> ShakePlus r a
$creturn :: forall r a. a -> ShakePlus r a
>> :: ShakePlus r a -> ShakePlus r b -> ShakePlus r b
$c>> :: forall r a b. ShakePlus r a -> ShakePlus r b -> ShakePlus r b
>>= :: ShakePlus r a -> (a -> ShakePlus r b) -> ShakePlus r b
$c>>= :: forall r a b.
ShakePlus r a -> (a -> ShakePlus r b) -> ShakePlus r b
$cp1Monad :: forall r. Applicative (ShakePlus r)
Monad, MonadReader r, Monad (ShakePlus r)
Monad (ShakePlus r)
-> (forall a. IO a -> ShakePlus r a) -> MonadIO (ShakePlus r)
IO a -> ShakePlus r a
forall r. Monad (ShakePlus r)
forall a. IO a -> ShakePlus r a
forall r a. IO a -> ShakePlus r a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> ShakePlus r a
$cliftIO :: forall r a. IO a -> ShakePlus r a
$cp1MonadIO :: forall r. Monad (ShakePlus r)
MonadIO, Monad (ShakePlus r)
Monad (ShakePlus r)
-> (forall a. Rules a -> ShakePlus r a) -> MonadRules (ShakePlus r)
Rules a -> ShakePlus r a
forall r. Monad (ShakePlus r)
forall a. Rules a -> ShakePlus r a
forall r a. Rules a -> ShakePlus r a
forall (m :: * -> *).
Monad m -> (forall a. Rules a -> m a) -> MonadRules m
liftRules :: Rules a -> ShakePlus r a
$cliftRules :: forall r a. Rules a -> ShakePlus r a
$cp1MonadRules :: forall r. Monad (ShakePlus r)
MonadRules)

-- | Run an `RAction` with an environment, consuming it for a result.
runRAction :: MonadAction m => env -> RAction env a -> m a
runRAction :: env -> RAction env a -> m a
runRAction env
r (RAction (ReaderT env -> Action a
f)) = Action a -> m a
forall (m :: * -> *) a. MonadAction m => Action a -> m a
liftAction (env -> Action a
f env
r)

-- | Run a `ShakePlus` with an environment, consuming it for some Shake `Rules`.
runShakePlus :: MonadRules m => env -> ShakePlus env a -> m a
runShakePlus :: env -> ShakePlus env a -> m a
runShakePlus env
r (ShakePlus (ReaderT env -> Rules a
f)) = Rules a -> m a
forall (m :: * -> *) a. MonadRules m => Rules a -> m a
liftRules (env -> Rules a
f env
r)

instance MonadThrow (RAction r) where
  throwM :: e -> RAction r a
throwM = IO a -> RAction r a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> RAction r a) -> (e -> IO a) -> e -> RAction r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> IO a
forall e a. Exception e => e -> IO a
Control.Exception.throwIO

instance MonadThrow (ShakePlus r) where
  throwM :: e -> ShakePlus r a
throwM = IO a -> ShakePlus r a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> ShakePlus r a) -> (e -> IO a) -> e -> ShakePlus r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> IO a
forall e a. Exception e => e -> IO a
Control.Exception.throwIO

-- | Unlifted `Development.Shake.parallel`.
parallel :: MonadUnliftAction m => [m a] -> m [a]
parallel :: [m a] -> m [a]
parallel [m a]
xs = ((forall a. m a -> Action a) -> Action [a]) -> m [a]
forall (m :: * -> *) b.
MonadUnliftAction m =>
((forall a. m a -> Action a) -> Action b) -> m b
withRunInAction (((forall a. m a -> Action a) -> Action [a]) -> m [a])
-> ((forall a. m a -> Action a) -> Action [a]) -> m [a]
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> Action a
run -> [Action a] -> Action [a]
forall a. [Action a] -> Action [a]
Development.Shake.parallel ([Action a] -> Action [a]) -> [Action a] -> Action [a]
forall a b. (a -> b) -> a -> b
$ (m a -> Action a) -> [m a] -> [Action a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m a -> Action a
forall a. m a -> Action a
run [m a]
xs

-- | Unlifted `Development.Shake.forP`.
forP :: MonadUnliftAction m => [a] -> (a -> m b) -> m [b]
forP :: [a] -> (a -> m b) -> m [b]
forP [a]
x a -> m b
f = ((forall a. m a -> Action a) -> Action [b]) -> m [b]
forall (m :: * -> *) b.
MonadUnliftAction m =>
((forall a. m a -> Action a) -> Action b) -> m b
withRunInAction (((forall a. m a -> Action a) -> Action [b]) -> m [b])
-> ((forall a. m a -> Action a) -> Action [b]) -> m [b]
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> Action a
run -> [a] -> (a -> Action b) -> Action [b]
forall a b. [a] -> (a -> Action b) -> Action [b]
Development.Shake.forP [a]
x ((a -> Action b) -> Action [b]) -> (a -> Action b) -> Action [b]
forall a b. (a -> b) -> a -> b
$ m b -> Action b
forall a. m a -> Action a
run (m b -> Action b) -> (a -> m b) -> a -> Action b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m b
f

-- | Unlifted `Development.Shake.par`.
par :: MonadUnliftAction m => m a -> m b -> m (a, b)
par :: m a -> m b -> m (a, b)
par m a
a m b
b = ((forall a. m a -> Action a) -> Action (a, b)) -> m (a, b)
forall (m :: * -> *) b.
MonadUnliftAction m =>
((forall a. m a -> Action a) -> Action b) -> m b
withRunInAction (((forall a. m a -> Action a) -> Action (a, b)) -> m (a, b))
-> ((forall a. m a -> Action a) -> Action (a, b)) -> m (a, b)
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> Action a
run -> Action a -> Action b -> Action (a, b)
forall a b. Action a -> Action b -> Action (a, b)
Development.Shake.par (m a -> Action a
forall a. m a -> Action a
run m a
a) (m b -> Action b
forall a. m a -> Action a
run m b
b)