Skip to content

Instantly share code, notes, and snippets.

@owen-d
Created July 21, 2019 18:38
Show Gist options
  • Save owen-d/ad106a405b0ecf91463b14e616d19db6 to your computer and use it in GitHub Desktop.
Save owen-d/ad106a405b0ecf91463b14e616d19db6 to your computer and use it in GitHub Desktop.
contiguous sublists of n length in haskell
sublists :: Int -> [a] -> [[a]]
sublists n xs = filter (\x -> length x == n) $ contiguous n xs
where
contiguous _ [] = []
contiguous n (x:xs) =
take n (x:xs) : contiguous n xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment