Skip to content

Batch with overlap #1005

Closed Answered by atifaziz
matyasbach asked this question in Q&A
Jun 16, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

You can use WindowLeft with TakeEvery like so:

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 Buffer from System.Interactive instead.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@matyasbach
Comment options

@atifaziz
Comment options

@matyasbach
Comment options

Answer selected by atifaziz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants