module Polysemy.Conc.Effect.Lock where
data Lock :: Effect where
Lock :: m a -> Lock m a
LockOr :: m a -> m a -> Lock m a
makeSem_ ''Lock
lock ::
∀ r a .
Member Lock r =>
Sem r a ->
Sem r a
lockOr ::
∀ r a .
Member Lock r =>
Sem r a ->
Sem r a ->
Sem r a
lockOrSkip ::
∀ r a .
Member Lock r =>
Sem r a ->
Sem r (Maybe a)
lockOrSkip :: forall (r :: EffectRow) a.
Member Lock r =>
Sem r a -> Sem r (Maybe a)
lockOrSkip Sem r a
ma =
Sem r (Maybe a) -> Sem r (Maybe a) -> Sem r (Maybe a)
forall (r :: EffectRow) a.
Member Lock r =>
Sem r a -> Sem r a -> Sem r a
lockOr (Maybe a -> Sem r (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing) (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Sem r a -> Sem r (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sem r a
ma)
{-# inline lockOrSkip #-}
lockOrSkip_ ::
∀ r a .
Member Lock r =>
Sem r a ->
Sem r ()
lockOrSkip_ :: forall (r :: EffectRow) a. Member Lock r => Sem r a -> Sem r ()
lockOrSkip_ Sem r a
ma =
Sem r () -> Sem r () -> Sem r ()
forall (r :: EffectRow) a.
Member Lock r =>
Sem r a -> Sem r a -> Sem r a
lockOr Sem r ()
forall (f :: * -> *). Applicative f => f ()
unit (Sem r a -> Sem r ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Sem r a
ma)
{-# inline lockOrSkip_ #-}