Created
December 9, 2020 16:40
-
-
Save derrickturk/ffecfa66c181e03075d9395f9fc433e7 to your computer and use it in GitHub Desktop.
Sliding-windows in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
takeExactly :: Int -> [a] -> Maybe [a] | |
takeExactly 0 _ = Just [] | |
takeExactly n [] = Nothing | |
takeExactly n (x:xs) = (x:) <$> takeExactly (n - 1) xs | |
windows :: Int -> [a] -> [[a]] | |
windows n xs = case takeExactly n xs of | |
Nothing -> [] | |
Just window -> window:windows n (tail xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment