never executed always true always false
1 {-|
2 Module: Y2015.Util
3 Description: Shared functions for Advent of Code Solutions.
4 License: MIT
5 Maintainer: @tylerjl
6
7 Shared functions that support solutions to problems for the
8 <adventofcode.com> challenges.
9 -}
10
11 module Y2015.Util
12 ( (<&&>)
13 , (<||>)
14 , regularParse
15 , intParser
16 , regularParse'
17 ,intParser') where
18
19 import Control.Monad (liftM2)
20 import qualified Text.Parsec as P
21 import Text.Parsec.Char (digit)
22 import Text.Parsec.String (Parser)
23 import qualified Text.Parsec.Text as T
24 import Data.Text (Text)
25
26 -- |Combinator operator for predicates
27 (<&&>) :: (a -> Bool) -- ^ Predicate 1
28 -> (a -> Bool) -- ^ Predicate 2
29 -> a -- ^ Predicate target
30 -> Bool -- ^ Logical and for predicates
31 (<&&>) = liftM2 (&&)
32
33 -- |Combinator operator for predicates
34 (<||>) :: (a -> Bool) -- ^ Predicate 1
35 -> (a -> Bool) -- ^ Predicate 2
36 -> a -- ^ Predicate target
37 -> Bool -- ^ Logical or for predicates
38 (<||>) = liftM2 (||)
39
40 -- |Generic parsing wrapper
41 regularParse :: Parser a -> String -> Either P.ParseError a
42 regularParse p = P.parse p ""
43
44 -- |Generic parser for `Text` values
45 regularParse' :: T.Parser a -> Text -> Either P.ParseError a
46 regularParse' p = P.parse p ""
47
48 -- |Generic 'Int' parser
49 intParser :: Parser Int -- ^ Parsec parser for 'Int' types
50 intParser = read <$> P.many1 digit
51
52 -- |Generic 'Int' parser for `Text`
53 intParser' :: T.Parser Int -- ^ Parsec parser for 'Int' types
54 intParser' = read <$> P.many1 digit