Batch with overlap #1005
Batch with overlap
#1005
-
Hi! Is there any simple way to chunkify IEnumerable with some overlap? Or can I propose API like bellow or try to do PR? var input = new [] { 1, 2, 3, 4, 5, 6 };
var result = input.Batch(3, overlap: 1); // => [[1, 2, 3], [3, 4, 5], [5, 6]] Basically something between Batch() and Window(). |
Beta Was this translation helpful? Give feedback.
Answered by
atifaziz
Jun 16, 2023
Replies: 2 comments 3 replies
-
@matyasbach This is available already in SuperLinq under the |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can use var input = new [] { 1, 2, 3, 4, 5, 6 };
var result = input.WindowLeft(3).TakeEvery(2);
Console.WriteLine($"[{result.Select(w => $"[{w.ToDelimitedString(", ")}]")
.ToDelimitedString(", ")}]");
// => [[1, 2, 3], [3, 4, 5], [5, 6]] However, creating windows only to skip some may be a bit wasteful so you may want to use |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
atifaziz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
WindowLeft
withTakeEvery
like so:However, creating windows only to skip some may be a bit wasteful so you may want to use
Buffer
from System.Interactive instead.