day16/haskell: rename iterateUntilDone to iterateUntilNothing
This commit is contained in:
parent
499c02756e
commit
477f518531
1 changed files with 3 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue