day16/haskell: prettify findSingletonChoice
This commit is contained in:
parent
d24d672f70
commit
5cbd457ebc
1 changed files with 6 additions and 5 deletions
|
@ -66,11 +66,12 @@ resolve = sequence . map fromResolved . iterateUntilNothing resolve' . map (Choi
|
||||||
fromResolved _ = Nothing
|
fromResolved _ = Nothing
|
||||||
|
|
||||||
findSingletonChoice :: [Resolve a] -> Maybe (a, [Resolve a])
|
findSingletonChoice :: [Resolve a] -> Maybe (a, [Resolve a])
|
||||||
findSingletonChoice (c@(Choice s):xs) | S.size s == 1 = let [x] = S.elems s
|
findSingletonChoice [] = Nothing
|
||||||
in Just (x, Resolved x:xs)
|
findSingletonChoice (x:xs) =
|
||||||
| otherwise = (fmap.fmap) (c:) $ findSingletonChoice xs
|
case x of
|
||||||
findSingletonChoice (x:xs) = (fmap.fmap) (x:) $ findSingletonChoice xs
|
Choice s | S.size s == 1 -> let [r] = S.elems s
|
||||||
findSingletonChoice _ = Nothing
|
in Just (r, Resolved r : xs)
|
||||||
|
_ -> fmap (\(r, rest) -> (r, x:rest)) $ findSingletonChoice xs
|
||||||
|
|
||||||
resolve' :: Ord a => [Resolve a] -> Maybe [Resolve a]
|
resolve' :: Ord a => [Resolve a] -> Maybe [Resolve a]
|
||||||
resolve' xs = do
|
resolve' xs = do
|
||||||
|
|
Loading…
Reference in a new issue