diff --git a/src/PreludeExtra.hs b/src/PreludeExtra.hs index 6a07f0e..d076917 100644 --- a/src/PreludeExtra.hs +++ b/src/PreludeExtra.hs @@ -14,6 +14,8 @@ import Data.Foldable as Exports import Control.Arrow as Exports import Control.Concurrent as Exports import Control.Concurrent.STM as Exports hiding (atomically) +import Safe as Exports +import Control.Monad.Trans.Maybe as Exports import Data.Char as Exports import Text.Read as Exports (readMaybe) @@ -68,9 +70,7 @@ useTraverseM_ aLens f = traverseM_ (use aLens) f exhaustTChan :: TChan a -> STM [a] -exhaustTChan chan = tryReadTChan chan >>= \case - Just a -> (a:) <$> exhaustTChan chan - Nothing -> return [] +exhaustTChan = fmap (fromJustNote "many") . runMaybeT . many . MaybeT . tryReadTChan atomically :: MonadIO m => STM a -> m a atomically = liftIO . STM.atomically