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

{-# LANGUAGE ScopedTypeVariables #-}

module Streamly.Internal.Control.Monad
    ( discard
    )
where

import Control.Monad (void)
import Control.Monad.Catch (MonadCatch, catch, SomeException)

-- | Discard any exceptions or value returned by an effectful action.
--
-- /Internal/
--
{-# INLINE discard #-}
discard :: MonadCatch m => m b -> m ()
discard :: m b -> m ()
discard m b
action = (m b -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m b -> m ()) -> m b -> m ()
forall a b. (a -> b) -> a -> b
$ m b
action) m () -> (SomeException -> m ()) -> m ()
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`catch` (\(SomeException
_ :: SomeException) -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())