public static IEnumerable<IList<TSource>> WindowRight<TSource>(
this IEnumerable<TSource> source,
int size
)
<ExtensionAttribute>
Public Shared Function WindowRight(Of TSource) (
source As IEnumerable(Of TSource),
size As Integer
) As IEnumerable(Of IList(Of TSource))
public:
[ExtensionAttribute]
generic<typename TSource>
static IEnumerable<IList<TSource>^>^ WindowRight(
IEnumerable<TSource>^ source,
int size
)
[<ExtensionAttribute>]
static member WindowRight :
source : IEnumerable<'TSource> *
size : int -> IEnumerable<IList<'TSource>>
A window can contain fewer elements than size, especially as it slides over the start of the sequence.
This operator uses deferred execution and streams its results.
Console.WriteLine(
Enumerable
.Range(1, 5)
.WindowRight(3)
.Select(w => "AVG(" + w.ToDelimitedString(",") + ") = " + w.Average())
.ToDelimitedString(Environment.NewLine));
// Output:
// AVG(1) = 1
// AVG(1,2) = 1.5
// AVG(1,2,3) = 2
// AVG(2,3,4) = 3
// AVG(3,4,5) = 4