-
Notifications
You must be signed in to change notification settings - Fork 1
behavior of .windows
when window size exceeds iterator length
#13
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
Comments
Why is it weird to yield a too-small window as the final result? That's what I'd expect, I think. |
I'd expect the return type of |
Which is more likely, though - a mistake caused by not noticing that your iterator doesn't yield complete chunks, or, one caused by not noticing that a partial chunk was dropped? This probably calls for an option, if the dropping behavior is needed. |
I think the default should be that if you ask for a window of 5 items, you need 5 items to get a window. In Kotlin you have to opt in to "partialWindows": https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/windowed.html val partialWindows = sequence.take(10).windowed(size = 5, step = 3, partialWindows = true)
println(partialWindows.toList()) // [[1, 2, 3, 4, 5], [4, 5, 6, 7, 8], [7, 8, 9, 10], [10]] Having an options bag to choose a mode would align with https://github.com/tc39/proposal-joint-iteration, which currently defaults to "shortest", dropping values that can't be zipped with anything. With windows having an option to choose the padding may also be useful, i.e. choosing |
What happens if you do
[1, 2].values().windows(3)
?Current spec says this gives you an empty iterator (i.e., no windows at all). As the readme documents, behavior in other languages varies.
My intuition is that it's weird to drop items, but it's also weird to yield a too-small window. I'm not sure what the right behavior is. Throwing is a possibility.
The text was updated successfully, but these errors were encountered: