@@ -0,0 +1,27 @@
1+-- |
2+-- Module : Streamly.Internal.Control.Monad
3+-- Copyright : (c) 2019 Composewell Technologies
4+--
5+-- License : BSD3
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
8+-- Portability : GHC
9+--
10+-- Additional "Control.Monad" utilities.
11+
12+{-# LANGUAGE ScopedTypeVariables #-}
13+
14+module Streamly.Internal.Control.Monad
15+ ( discard
16+ )
17+where
18+
19+import Control.Monad (void)
20+import Control.Monad.Catch (MonadCatch, catch, SomeException)
21+
22+-- | Discard any exceptions or value returned by an effectful action.
23+--
24+-- /Internal/
25+--
26+discard :: MonadCatch m => m b -> m ()
27+discard action = (void $ action) `catch` (\(_ :: SomeException) -> return ())