From 01afdce7ef70406830940052c63b94d8c4769f2f Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 5 Dec 2020 10:21:09 +0100 Subject: [PATCH] haskell: move oneCompleteResult to AoC module --- 2020/day4/day4.hs | 5 ----- common/AoC.hs | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/2020/day4/day4.hs b/2020/day4/day4.hs index b2baa8a..36b935f 100644 --- a/2020/day4/day4.hs +++ b/2020/day4/day4.hs @@ -89,11 +89,6 @@ parseFieldNames = spaceSeparated parseFieldName parsePassport :: ReadP [Field] 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 = map (intercalate " ") . filter (not . any null) . groupBy ((==) `on` null) . lines diff --git a/common/AoC.hs b/common/AoC.hs index b687673..bdc48cf 100644 --- a/common/AoC.hs +++ b/common/AoC.hs @@ -1,9 +1,16 @@ module AoC where +import Text.ParserCombinators.ReadP + (.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d f .: g = (f .) . g 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 inputTransform part1 part2 = do contents <- inputTransform <$> getContents