From ff3068d52fb917f0f37389f8e35ec88f4ec66eaf Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Wed, 18 Dec 2024 17:43:52 -0600 Subject: [PATCH] fix partiality warning --- src/Data/Colour/Palette/RandomColor.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Data/Colour/Palette/RandomColor.hs b/src/Data/Colour/Palette/RandomColor.hs index 9336d08..743584b 100644 --- a/src/Data/Colour/Palette/RandomColor.hs +++ b/src/Data/Colour/Palette/RandomColor.hs @@ -41,6 +41,7 @@ import Data.Colour.Palette.Types import Data.Colour.RGBSpace.HSV import Data.Colour.SRGB (RGB (..), sRGB) import Data.List (find) +import qualified Data.List.NonEmpty as NE import Data.Maybe (fromMaybe) getColorDefinition :: Hue -> ColorDefinition @@ -106,9 +107,9 @@ saturationRange :: Hue -> (Int, Int) saturationRange hue = result where lbs = lowerBounds $ getColorDefinition hue - result = case lbs of - [] -> error "Can\'t obtain saturationRange from an empty lowerBounds" - _ -> (fst . head $ lbs, fst . last $ lbs) + result = case NE.nonEmpty lbs of + Nothing -> error "Can\'t obtain saturationRange from an empty lowerBounds" + Just lbsNE -> (fst . NE.head $ lbsNE, fst . NE.last $ lbsNE) randomSaturation :: MonadRandom m => Hue -> Luminosity -> m Int randomSaturation HueMonochrome _ = return 0