From b32a10b62f57362e72bbc76942c671841418ba30 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 16 Dec 2020 17:48:23 +0100 Subject: [PATCH] 2020 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