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.
Replies: 2 comments 3 replies
-
@matyasbach This is available already in SuperLinq under the |
Beta Was this translation helpful? Give feedback.
-
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.
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.