2020 day16/haskell: rename iterateUntilDone to iterateUntilNothing
This commit is contained in:
parent
fb8094d5f4
commit
b32a10b62f
1 changed files with 3 additions and 5 deletions
|
@ -55,15 +55,13 @@ parseInput = do
|
||||||
matchesAnyField :: [Field] -> Int -> Bool
|
matchesAnyField :: [Field] -> Int -> Bool
|
||||||
matchesAnyField fields n = any (n `S.member`) . map valids $ fields
|
matchesAnyField fields n = any (n `S.member`) . map valids $ fields
|
||||||
|
|
||||||
iterateUntilDone :: (a -> Maybe a) -> a -> a
|
iterateUntilNothing :: (a -> Maybe a) -> a -> a
|
||||||
iterateUntilDone f x = case f x of
|
iterateUntilNothing f x = maybe x (iterateUntilNothing f) $ f x
|
||||||
Just x' -> iterateUntilDone f x'
|
|
||||||
Nothing -> x
|
|
||||||
|
|
||||||
data Resolve a = Resolved a | Choice (Set a) deriving (Show)
|
data Resolve a = Resolved a | Choice (Set a) deriving (Show)
|
||||||
|
|
||||||
resolve :: Ord a => [[a]] -> Maybe [a]
|
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
|
where fromResolved (Resolved x) = Just x
|
||||||
fromResolved _ = Nothing
|
fromResolved _ = Nothing
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue