haskell: move splitOnEmptyLines to AoC.hs

This commit is contained in:
Xiretza 2020-12-06 07:36:19 +01:00
parent 24556ff78d
commit ecf310c031
2 changed files with 5 additions and 5 deletions

View file

@ -3,8 +3,6 @@ import AoC
import Control.Applicative ((<|>))
import Control.Monad (guard, mfilter)
import Data.Char (isDigit)
import Data.Function (on)
import Data.List (groupBy, intercalate)
import Data.Maybe (mapMaybe)
import Text.ParserCombinators.ReadP
import Text.Read (readMaybe)
@ -89,9 +87,6 @@ parseFieldNames = spaceSeparated parseFieldName
parsePassport :: ReadP [Field]
parsePassport = spaceSeparated parseField
splitOnEmptyLines :: String -> [String]
splitOnEmptyLines = map (intercalate " ") . filter (not . any null) . groupBy ((==) `on` null) . lines
hasAllRequiredFields :: String -> Bool
hasAllRequiredFields = maybe False containsAllFields . fieldNames
where requiredFieldNames = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"]

View file

@ -1,5 +1,7 @@
module AoC where
import Data.Function (on)
import Data.List (groupBy, intercalate)
import Text.ParserCombinators.ReadP
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
@ -11,6 +13,9 @@ 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
runAoC :: (Show r1, Show r2) => (String -> i) -> (i -> r1) -> (i -> r2) -> IO ()
runAoC inputTransform part1 part2 = do
contents <- inputTransform <$> getContents