day16/haskell: rename iterateUntilDone to iterateUntilNothing

This commit is contained in:
Xiretza 2020-12-16 17:48:23 +01:00
parent 499c02756e
commit 477f518531

View file

@ -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