haskell: move oneCompleteResult to AoC module

This commit is contained in:
Xiretza 2020-12-05 10:21:09 +01:00
parent 1e30302115
commit 01afdce7ef
2 changed files with 7 additions and 5 deletions

View file

@ -89,11 +89,6 @@ parseFieldNames = spaceSeparated parseFieldName
parsePassport :: ReadP [Field] parsePassport :: ReadP [Field]
parsePassport = spaceSeparated parseField parsePassport = spaceSeparated parseField
oneCompleteResult :: ReadP a -> String -> Maybe a
oneCompleteResult p s = case readP_to_S (p <* eof) s of
[(x, "")] -> Just x
_ -> Nothing
splitOnEmptyLines :: String -> [String] splitOnEmptyLines :: String -> [String]
splitOnEmptyLines = map (intercalate " ") . filter (not . any null) . groupBy ((==) `on` null) . lines splitOnEmptyLines = map (intercalate " ") . filter (not . any null) . groupBy ((==) `on` null) . lines

View file

@ -1,9 +1,16 @@
module AoC where module AoC where
import Text.ParserCombinators.ReadP
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d (.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
f .: g = (f .) . g f .: g = (f .) . g
infixl 8 .: infixl 8 .:
oneCompleteResult :: ReadP a -> String -> Maybe a
oneCompleteResult p s = case readP_to_S (p <* eof) s of
[(x, "")] -> Just x
_ -> Nothing
runAoC :: (Show r1, Show r2) => (String -> i) -> (i -> r1) -> (i -> r2) -> IO () runAoC :: (Show r1, Show r2) => (String -> i) -> (i -> r1) -> (i -> r2) -> IO ()
runAoC inputTransform part1 part2 = do runAoC inputTransform part1 part2 = do
contents <- inputTransform <$> getContents contents <- inputTransform <$> getContents