streamly-core-0.1.0: src/Streamly/Internal/Control/Exception.hs
-- |
-- Module : Streamly.Internal.Control.Exception
-- Copyright : (c) 2019 Composewell Technologies
--
-- License : BSD3
-- Maintainer : streamly@composewell.com
-- 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 ())