module Effectful.Temporary
(
Temporary
, runTemporary
, withSystemTempFile
, withSystemTempDirectory
, withTempFile
, withTempDirectory
) where
import System.IO
import qualified UnliftIO.Temporary as T
import Effectful
import Effectful.Dispatch.Static
data Temporary :: Effect
type instance DispatchOf Temporary = Static WithSideEffects
data instance StaticRep Temporary = Temporary
runTemporary :: IOE :> es => Eff (Temporary : es) a -> Eff es a
runTemporary :: forall (es :: [Effect]) a.
(IOE :> es) =>
Eff (Temporary : es) a -> Eff es a
runTemporary = forall (e :: Effect) (sideEffects :: SideEffects) (es :: [Effect])
a.
(DispatchOf e ~ 'Static sideEffects, MaybeIOE sideEffects es) =>
StaticRep e -> Eff (e : es) a -> Eff es a
evalStaticRep StaticRep Temporary
Temporary
withSystemTempFile
:: Temporary :> es
=> String
-> (FilePath -> Handle -> Eff es a)
-> Eff es a
withSystemTempFile :: forall (es :: [Effect]) a.
(Temporary :> es) =>
String -> (String -> Handle -> Eff es a) -> Eff es a
withSystemTempFile String
template String -> Handle -> Eff es a
action = forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
forall (m :: Type -> Type) a.
MonadUnliftIO m =>
String -> (String -> Handle -> m a) -> m a
T.withSystemTempFile String
template forall a b. (a -> b) -> a -> b
$ \String
fp Handle
handle -> forall r. Eff es r -> IO r
unlift forall a b. (a -> b) -> a -> b
$ String -> Handle -> Eff es a
action String
fp Handle
handle
withSystemTempDirectory
:: Temporary :> es
=> String
-> (FilePath -> Eff es a)
-> Eff es a
withSystemTempDirectory :: forall (es :: [Effect]) a.
(Temporary :> es) =>
String -> (String -> Eff es a) -> Eff es a
withSystemTempDirectory String
template String -> Eff es a
action = forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
forall (m :: Type -> Type) a.
MonadUnliftIO m =>
String -> (String -> m a) -> m a
T.withSystemTempDirectory String
template forall a b. (a -> b) -> a -> b
$ \String
fp -> forall r. Eff es r -> IO r
unlift forall a b. (a -> b) -> a -> b
$ String -> Eff es a
action String
fp
withTempFile
:: Temporary :> es
=> FilePath
-> String
-> (FilePath -> Handle -> Eff es a)
-> Eff es a
withTempFile :: forall (es :: [Effect]) a.
(Temporary :> es) =>
String -> String -> (String -> Handle -> Eff es a) -> Eff es a
withTempFile String
tmpDir String
template String -> Handle -> Eff es a
action = forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
forall (m :: Type -> Type) a.
MonadUnliftIO m =>
String -> String -> (String -> Handle -> m a) -> m a
T.withTempFile String
tmpDir String
template forall a b. (a -> b) -> a -> b
$ \String
fp Handle
handle -> forall r. Eff es r -> IO r
unlift forall a b. (a -> b) -> a -> b
$ String -> Handle -> Eff es a
action String
fp Handle
handle
withTempDirectory
:: Temporary :> es
=> FilePath
-> String
-> (FilePath -> Eff es a)
-> Eff es a
withTempDirectory :: forall (es :: [Effect]) a.
(Temporary :> es) =>
String -> String -> (String -> Eff es a) -> Eff es a
withTempDirectory String
tmpDir String
template String -> Eff es a
action = forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
forall (m :: Type -> Type) a.
MonadUnliftIO m =>
String -> String -> (String -> m a) -> m a
T.withTempDirectory String
tmpDir String
template forall a b. (a -> b) -> a -> b
$ \String
fp -> forall r. Eff es r -> IO r
unlift forall a b. (a -> b) -> a -> b
$ String -> Eff es a
action String
fp