{- | An effect modelling nondeterminism without choice (success or failure).

This can be seen as similar to 'Control.Effect.Fail.Fail', but without an error message. The 'Control.Effect.NonDet.NonDet' effect is the composition of 'Empty' and 'Control.Effect.Choose.Choose'.

Predefined carriers:

* @"Control.Carrier.Empty.Church".'Control.Carrier.Empty.Church.EmptyC'@
* @"Control.Carrier.Empty.Maybe".'Control.Carrier.Empty.Maybe.EmptyC'@
* @"Control.Monad.Trans.Maybe".'Control.Monad.Trans.Maybe.MaybeT'@
* If 'Empty' is the last effect in a stack, it can be interpreted directly to a 'Maybe'.

@since 1.0.0.0
-}

module Control.Effect.Empty
( -- * Empty effect
  Empty(..)
, empty
, guard
  -- * Re-exports
, Algebra
, Has
, run
) where

import Control.Algebra
import Control.Effect.Empty.Internal (Empty(..))

-- | Abort the computation.
--
-- 'empty' annihilates '>>=':
--
-- @
-- 'empty' '>>=' k = 'empty'
-- @
--
-- @since 1.0.0.0
empty :: Has Empty sig m => m a
empty :: m a
empty = Empty m a -> m a
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send Empty m a
forall (m :: * -> *) a. Empty m a
Empty
{-# INLINE empty #-}

-- | Conditional failure, returning only if the condition is 'True'.
--
-- @since 1.0.0.0
guard :: Has Empty sig m => Bool -> m ()
guard :: Bool -> m ()
guard Bool
True  = () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
guard Bool
False = m ()
forall (sig :: (* -> *) -> * -> *) (m :: * -> *) a.
Has Empty sig m =>
m a
empty
{-# INLINE guard #-}