Move some utilities out of Day4.hs
This commit is contained in:
parent
99de1c4d40
commit
41f0b8d511
@ -39,6 +39,9 @@ module Pre (
|
||||
module Text.Megaparsec.Char.Lexer,
|
||||
module Text.Pretty.Simple,
|
||||
Puzzle (..),
|
||||
(<<$>>),
|
||||
(<<&>>),
|
||||
takeUntil,
|
||||
digit,
|
||||
digitsToInt,
|
||||
listIndex,
|
||||
@ -138,6 +141,14 @@ data Puzzle = forall input outputs. (KnownNat (Length outputs), NFData input) =>
|
||||
, extraTests :: Bool -> FilePath -> [TestTree IO (input, HList outputs)]
|
||||
}
|
||||
|
||||
(<<$>>) :: (Functor f1, Functor f2) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)
|
||||
(<<$>>) = fmap . fmap
|
||||
(<<&>>) :: (Functor f1, Functor f2) => f1 (f2 a) -> (a -> b) -> f1 (f2 b)
|
||||
(<<&>>) = flip (<<$>>)
|
||||
|
||||
takeUntil :: (Foldable t) => (a -> Bool) -> t a -> [a]
|
||||
takeUntil p = foldr (\x xs -> x : if p x then [] else xs) []
|
||||
|
||||
digit :: (Token s ~ Char, Num b, MonadParsec e s f) => f b
|
||||
digit = fromIntegral . digitToInt <$> digitChar
|
||||
|
||||
|
||||
@ -123,13 +123,5 @@ noneAccessible (Grid g) = not $ any (elem OutAccessible . fmap snd) g
|
||||
countRolls :: Grid InTile -> Int
|
||||
countRolls (Grid g) = length $ concatMap (filter (== InRoll) . toList . fmap snd) g
|
||||
|
||||
(<<$>>) :: (Functor f1, Functor f2) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)
|
||||
(<<$>>) = fmap . fmap
|
||||
(<<&>>) :: (Functor f1, Functor f2) => f1 (f2 a) -> (a -> b) -> f1 (f2 b)
|
||||
(<<&>>) = flip (<<$>>)
|
||||
|
||||
takeUntil :: (Foldable t) => (a -> Bool) -> t a -> [a]
|
||||
takeUntil p = foldr (\x xs -> x : if p x then [] else xs) []
|
||||
|
||||
unfoldMutual :: (a -> b) -> (b -> a) -> a -> Stream (a, b)
|
||||
unfoldMutual f g a = let b = f a in (a, b) :> unfoldMutual f g (g b)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user