acquire-0.3.6: Abstraction over management of resources
Safe HaskellSafe-Inferred
LanguageHaskell2010

Acquire

Contents

Synopsis

IO

acquire :: Acquire a -> IO a Source #

Acquire resources and use them by lifting IO into acquire.

acquireAndUse :: Acquire env -> Use env err res -> IO (Either err res) Source #

Execute an action, which uses a resource, having a resource provider.

useAcquired :: env -> Use env err res -> IO (Either err res) Source #

Run use on an acquired environment.

Acquire

newtype Acquire env Source #

Resource provider. Abstracts over resource acquisition and releasing.

Composes well, allowing you to merge multiple providers into one.

Implementation of http://www.haskellforall.com/2013/06/the-resource-applicative.html

Constructors

Acquire (IO (env, IO ())) 

Instances

Instances details
MonadIO Acquire Source # 
Instance details

Defined in Acquire

Methods

liftIO :: IO a -> Acquire a #

Applicative Acquire Source # 
Instance details

Defined in Acquire

Methods

pure :: a -> Acquire a #

(<*>) :: Acquire (a -> b) -> Acquire a -> Acquire b #

liftA2 :: (a -> b -> c) -> Acquire a -> Acquire b -> Acquire c #

(*>) :: Acquire a -> Acquire b -> Acquire b #

(<*) :: Acquire a -> Acquire b -> Acquire a #

Functor Acquire Source # 
Instance details

Defined in Acquire

Methods

fmap :: (a -> b) -> Acquire a -> Acquire b #

(<$) :: a -> Acquire b -> Acquire a #

Monad Acquire Source # 
Instance details

Defined in Acquire

Methods

(>>=) :: Acquire a -> (a -> Acquire b) -> Acquire b #

(>>) :: Acquire a -> Acquire b -> Acquire b #

return :: a -> Acquire a #

startAndStop Source #

Arguments

:: IO a

Start the service.

-> (a -> IO ())

Stop the service.

-> Acquire a 

Construct Acquire by specifying a resource initializer and finalizer actions.

Use

newtype Use env err res Source #

Resource handler, which has a notion of pure errors.

Constructors

Use (ReaderT env (ExceptT err IO) res) 

Instances

Instances details
MonadError err (Use env err) Source # 
Instance details

Defined in Acquire

Methods

throwError :: err -> Use env err a #

catchError :: Use env err a -> (err -> Use env err a) -> Use env err a #

MonadReader env (Use env err) Source # 
Instance details

Defined in Acquire

Methods

ask :: Use env err env #

local :: (env -> env) -> Use env err a -> Use env err a #

reader :: (env -> a) -> Use env err a #

Bifunctor (Use env) Source # 
Instance details

Defined in Acquire

Methods

bimap :: (a -> b) -> (c -> d) -> Use env a c -> Use env b d #

first :: (a -> b) -> Use env a c -> Use env b c #

second :: (b -> c) -> Use env a b -> Use env a c #

MonadIO (Use env err) Source # 
Instance details

Defined in Acquire

Methods

liftIO :: IO a -> Use env err a #

Monoid err => Alternative (Use env err) Source # 
Instance details

Defined in Acquire

Methods

empty :: Use env err a #

(<|>) :: Use env err a -> Use env err a -> Use env err a #

some :: Use env err a -> Use env err [a] #

many :: Use env err a -> Use env err [a] #

Applicative (Use env err) Source # 
Instance details

Defined in Acquire

Methods

pure :: a -> Use env err a #

(<*>) :: Use env err (a -> b) -> Use env err a -> Use env err b #

liftA2 :: (a -> b -> c) -> Use env err a -> Use env err b -> Use env err c #

(*>) :: Use env err a -> Use env err b -> Use env err b #

(<*) :: Use env err a -> Use env err b -> Use env err a #

Functor (Use env err) Source # 
Instance details

Defined in Acquire

Methods

fmap :: (a -> b) -> Use env err a -> Use env err b #

(<$) :: a -> Use env err b -> Use env err a #

Monad (Use env err) Source # 
Instance details

Defined in Acquire

Methods

(>>=) :: Use env err a -> (a -> Use env err b) -> Use env err b #

(>>) :: Use env err a -> Use env err b -> Use env err b #

return :: a -> Use env err a #

Monoid err => MonadPlus (Use env err) Source # 
Instance details

Defined in Acquire

Methods

mzero :: Use env err a #

mplus :: Use env err a -> Use env err a -> Use env err a #

mapEnv :: (b -> a) -> Use a err res -> Use b err res Source #

Map the environment of a resource handler.

mapErr :: (a -> b) -> Use env a res -> Use env b res Source #

Map the error of a resource handler.

mapEnvAndErr :: (envB -> envA) -> (errA -> errB) -> Use envA errA res -> Use envB errB res Source #

Map both the environment and the error of a resource handler.