Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding window for lists #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Sliding window for lists #81

wants to merge 1 commit into from

Conversation

atifaziz
Copy link
Contributor

Propose to add window function for lists that provides a sliding window of a given size over the input. The result is an array of windows where is window is an array of always the given size.

Signature is:

Number -> [a] -> [[a]]

Usage:

[1 to 5] |> window 3
# => [ [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ] ]

@gkz
Copy link
Owner

gkz commented Mar 25, 2015

I have reservations about the name, as window is a global variable in the browser environment.

Also, I was wondering what kind of use-cases you envision.

@atifaziz
Copy link
Contributor Author

Could instead call it windowed as F# does.

One common use-case is of sliding window is calculating a moving average over, for example, time series, as in:

[Math.random! for i til 30] |> window 7 |> map mean

@atifaziz
Copy link
Contributor Author

Another suggestion for name would be windows unless the longer sliding-window seems clear & concise enough.

@michaelficarra
Copy link
Contributor

Related underscore.js proposals for _.sliding and _.groupsOf: jashkenas/underscore#714 jashkenas/underscore#696

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants