Method WindowLeft
WindowLeft<TSource>(IAsyncEnumerable<TSource>, int)
Creates a left-aligned sliding window of a given size over the source sequence.
Declaration
public static IAsyncEnumerable<IList<TSource>> WindowLeft<TSource>(this IAsyncEnumerable<TSource> source, int size)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncEnumerable<TSource> | source | The sequence over which to create the sliding window. |
| int | size | Size of the sliding window. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<IList<TSource>> | A sequence representing each sliding window. |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements of |
Remarks
A window can contain fewer elements than size,
especially as it slides over the end of the sequence.
This operator uses deferred execution and streams its results.
Examples
Console.WriteLine(
Enumerable
.Range(1, 5)
.WindowLeft(3)
.Select(w => "AVG(" + w.ToDelimitedString(",") + ") = " + w.Average())
.ToDelimitedString(Environment.NewLine));
// Output:
// AVG(1,2,3) = 2
// AVG(2,3,4) = 3
// AVG(3,4,5) = 4
// AVG(4,5) = 4.5
// AVG(5) = 5