From fa6036b401c46736087da19f22736129108a529b Mon Sep 17 00:00:00 2001 From: Anurag Hooda Date: Fri, 24 Dec 2021 07:00:14 +0000 Subject: [PATCH] Fix min to display error on empty stream --- src/Streamly/Statistics.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Streamly/Statistics.hs b/src/Streamly/Statistics.hs index a273608..6595d17 100644 --- a/src/Streamly/Statistics.hs +++ b/src/Streamly/Statistics.hs @@ -60,7 +60,10 @@ range ws = Fold.teeWith (-) (max ws) (min ws) -- | The minimum element in the sample. {-# INLINE min #-} min :: Monad m => WindowSize -> Fold m Double Double -min Infinite = Fold.foldl' step initial +min Infinite = Fold.teeWith + (\a b -> if a then error "Empty List" else b) + Fold.null + (Fold.foldl' step initial ) where initial = 1 / 0 step ma a