1 module Advent
.List
where
3 breakBy
:: ([a
] -> Bool) -> [a
] -> ([a
], [a
])
4 breakBy _
[] = ([], [])
8 let (ys
, zs
) = breakBy p xs
'
11 split :: Eq a
=> [a
] -> [a
] -> [[a
]]
14 let (x
, xs
) = breakBy
(\x
-> take (length delim
) x
== delim
) list
15 in x
: split delim
(drop (length delim
) xs
)
17 splitOne
:: Eq a
=> a
-> [a
] -> [[a
]]
18 splitOne delim
[] = []
20 let (x
, xs
) = break (==delim
) list
21 in x
: splitOne delim
(drop 1 xs
)
23 chunks
:: Int -> [a
] -> [[a
]]
25 chunks n xs
= take n xs
: chunks n
(drop n xs
)
27 count
:: (a
-> Bool) -> [a
] -> Int
28 count p
= length . filter p