Skip to content

Instantly share code, notes, and snippets.

@WillSewell
Last active August 29, 2015 14:05
Show Gist options
  • Save WillSewell/d77a0e0eb08be9a1d241 to your computer and use it in GitHub Desktop.
Save WillSewell/d77a0e0eb08be9a1d241 to your computer and use it in GitHub Desktop.
A Haskell foldl that slides a "window" over the list
-- f now takes a sliding sublist of values, rather than each value
-- n is the window size
winFold :: ([a] -> b -> b) -> b -> [a] -> Int -> b
winFold f acc n [] = acc
winFold f acc n xs = winFold f (f (take n xs) acc) (tail xs) n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment