From 477f518531ce096f8927246862122318f66092cd Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 16 Dec 2020 17:48:23 +0100 Subject: [PATCH] day16/haskell: rename iterateUntilDone to iterateUntilNothing --- 2020/day16/day16.hs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/2020/day16/day16.hs b/2020/day16/day16.hs index f8896a1..9ecf561 100644 --- a/2020/day16/day16.hs +++ b/2020/day16/day16.hs @@ -55,15 +55,13 @@ parseInput = do matchesAnyField :: [Field] -> Int -> Bool matchesAnyField fields n = any (n `S.member`) . map valids $ fields -iterateUntilDone :: (a -> Maybe a) -> a -> a -iterateUntilDone f x = case f x of - Just x' -> iterateUntilDone f x' - Nothing -> x +iterateUntilNothing :: (a -> Maybe a) -> a -> a +iterateUntilNothing f x = maybe x (iterateUntilNothing f) $ f x data Resolve a = Resolved a | Choice (Set a) deriving (Show) resolve :: Ord a => [[a]] -> Maybe [a] -resolve = sequence . map fromResolved . iterateUntilDone resolve' . map (Choice . S.fromList) +resolve = sequence . map fromResolved . iterateUntilNothing resolve' . map (Choice . S.fromList) where fromResolved (Resolved x) = Just x fromResolved _ = Nothing