Table of Contents

Method Window

Namespace
Gamelogic.Extensions.Algorithms
Assembly
Gamelogic.Extensions.dll

Window<TSource>(IGenerator<TSource>, int)

Makes a generator that generates a moving window of elements over a given generator.

public static IGenerator<TSource[]> Window<TSource>(this IGenerator<TSource> source, int windowSize)

Parameters

source IGenerator<TSource>

The source generator.

windowSize int

Size of the window.

Returns

IGenerator<TSource[]>

A new generator.

Type Parameters

TSource

The type of the source generator.

Examples

In the following example,

var generator = Generator.Count(4).Window(2);

the generator will generate (0 1) (1 2) (2 3) (3 0) (0 1)... The window of size 2 move one element (of the original generator) at a time.

The following is an implementation of a box blur on the given sequence:

public static IGenerator<float> BoxBlur(IGenerator<float> generator)
{
	return generator.Window(3).Select(w => (w[0] + w[1] + w[2])/3f);
}

Exceptions

ArgumentOutOfRangeException

windowSize;Argument must be positive.