-- |
  Module       : Streamly . Internal . Control . Exception
  Copyright    : ( c ) 2019 Composewell Technologies
--
-- License     : BSD3
-- Maintainer  : 
-- Stability   : experimental
  Portability : GHC
--
-- Additional "Control.Exception" utilities.

module Streamly.Internal.Control.Exception
    ( verify
    , verifyM
    )
where

-- | Like 'assert' but is not removed by the compiler, it is always present in
-- production code.
--
-- /Pre-release/
--
# INLINE verify #
verify :: Bool -> a -> a
verify predicate val =
    if predicate
    -- XXX it would be nice if we can print the predicate expr.
    then error "verify failed"
    else val

  Like ' verify ' but returns @()@ in an ' Applicative ' context so that it can be
-- used as an independent statement in a @do@ block.
--
-- /Pre-release/
--
# INLINE verifyM #
verifyM :: Applicative f => Bool -> f ()
verifyM predicate = verify predicate (pure ())

 |

 License     : BSD3
 Maintainer  : 
 Stability   : experimental

 Additional "Control.Exception" utilities.
 | Like 'assert' but is not removed by the compiler, it is always present in
 production code.

 /Pre-release/

 XXX it would be nice if we can print the predicate expr.
 used as an independent statement in a @do@ block.

 /Pre-release/

  Module       : Streamly . Internal . Control . Exception
  Copyright    : ( c ) 2019 Composewell Technologies
  Portability : GHC

module Streamly.Internal.Control.Exception
    ( verify
    , verifyM
    )
where

# INLINE verify #
verify :: Bool -> a -> a
verify predicate val =
    if predicate
    then error "verify failed"
    else val

  Like ' verify ' but returns @()@ in an ' Applicative ' context so that it can be
# INLINE verifyM #
verifyM :: Applicative f => Bool -> f ()
verifyM predicate = verify predicate (pure ())
