adventofcode-2021/14/Itertools.hs

15 lines
287 B
Haskell

module Itertools (
flatmap,
windows
) where
windows :: Int -> [a] -> [[a]]
windows _ [] = []
windows i (x:xs)
| length xs < i-1 = []
| otherwise = (x:take (i-1) xs):windows i xs
flatmap :: (t -> [a]) -> [t] -> [a]
flatmap _ [] = []
flatmap f (x:xs) = f x ++ flatmap f xs