Method WindowLeft
WindowLeft<TSource, TResult>(IEnumerable<TSource>, int, ReadOnlySpanFunc<TSource, TResult>)
Creates a right-aligned sliding window over the source sequence of a given size.
Declaration
public static IEnumerable<TResult> WindowLeft<TSource, TResult>(this IEnumerable<TSource> source, int size, SuperEnumerable.ReadOnlySpanFunc<TSource, TResult> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TSource> | source | The sequence over which to create the sliding window. |
| int | size | Size of the sliding window. |
| SuperEnumerable.ReadOnlySpanFunc<TSource, TResult> | selector | A transform function to apply to each window. |
Returns
| Type | Description |
|---|---|
| IEnumerable<TResult> | A sequence representing each sliding window. |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements of |
| TResult | The type of the value return by |
Remarks
A window can contain fewer elements than size, especially as it slides over the start of
the sequence.
In this overload of WindowLeft, a single array of length size is allocated as a
buffer for all subsequences.
This operator uses deferred execution and streams its results.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
WindowLeft<TSource, TResult>(IEnumerable<TSource>, TSource[], ReadOnlySpanFunc<TSource, TResult>)
Creates a right-aligned sliding window over the source sequence of a given size.
Declaration
public static IEnumerable<TResult> WindowLeft<TSource, TResult>(this IEnumerable<TSource> source, TSource[] array, SuperEnumerable.ReadOnlySpanFunc<TSource, TResult> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TSource> | source | The sequence over which to create the sliding window. |
| TSource[] | array | An array to use as a buffer for each subsequence. |
| SuperEnumerable.ReadOnlySpanFunc<TSource, TResult> | selector | A transform function to apply to each window. |
Returns
| Type | Description |
|---|---|
| IEnumerable<TResult> | A sequence representing each sliding window. |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements of |
| TResult | The type of the value return by |
Remarks
A window can contain fewer elements than , especially as it slides
over the start of the sequence.
array.Length
In this overload of WindowLeft, array is used as a common buffer for all
subsequences.
This operator uses deferred execution and streams its results.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
WindowLeft<TSource, TResult>(IEnumerable<TSource>, TSource[], int, ReadOnlySpanFunc<TSource, TResult>)
Creates a right-aligned sliding window over the source sequence of a given size.
Declaration
public static IEnumerable<TResult> WindowLeft<TSource, TResult>(this IEnumerable<TSource> source, TSource[] array, int size, SuperEnumerable.ReadOnlySpanFunc<TSource, TResult> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TSource> | source | The sequence over which to create the sliding window. |
| TSource[] | array | An array to use as a buffer for each subsequence. |
| int | size | Size of the sliding window. |
| SuperEnumerable.ReadOnlySpanFunc<TSource, TResult> | selector | A transform function to apply to each window. |
Returns
| Type | Description |
|---|---|
| IEnumerable<TResult> | A sequence representing each sliding window. |
Type Parameters
| Name | Description |
|---|---|
| TSource | The type of the elements of |
| TResult | The type of the value return by |
Remarks
A window can contain fewer elements than size, especially as it slides over the start of
the sequence.
In this overload of WindowLeft, array is used as a common buffer for all
subsequences.
This overload is provided to ease usage of common buffers, such as those rented from ArrayPool<T>, which may return an array larger than requested.
This operator uses deferred execution and streams its results.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
WindowLeft<TSource>(IEnumerable<TSource>, int)
Creates a left-aligned sliding window of a given size over the source sequence.
Declaration
public static IEnumerable<IList<TSource>> WindowLeft<TSource>(this IEnumerable<TSource> source, int size)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TSource> | source | The sequence over which to create the sliding window. |
| int | size | Size of the sliding window. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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
The following code example demonstrates how to generate a sliding window over a sequence using WindowLeft.
var sequence = Enumerable.Range(1, 10);
// Get a sliding window over the sequence
var result = sequence.WindowLeft(3);
Console.WriteLine(
"[" + Environment.NewLine +
string.Join(
", " + Environment.NewLine,
result.Select(c => " [" + string.Join(", ", c) + "]")) +
Environment.NewLine + "]");
// This code produces the following output:
// [
// [1, 2, 3],
// [2, 3, 4],
// [3, 4, 5],
// [4, 5, 6],
// [5, 6, 7],
// [6, 7, 8],
// [7, 8, 9],
// [8, 9, 10],
// [9, 10],
// [10]
// ]
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|