Table of Contents

Interface IGenerator<TResult>

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

All generic generators implement this interface.

[Version(2, 0, 0)]
public interface IGenerator<out TResult> : IGenerator

Type Parameters

TResult

The type of the elements the generator generates.

Inherited Members
Extension Methods

Remarks

Instances of IGenerator<TResult> are usually obtained from the static methods in the Generator. See [Generators](../content/Generators.md) for more information.

To correctly implement this interface:

  • A call to Current immediately after constructing the class must give the first element of the generator. This is in contrast to IEnumerator, where a call to MoveNext() must be made first.
  • Calls to Current must always give a valid element, no matter how many times MoveNext() has been called. Generators never end.
  • Calls to Current must always give the same value until the next call to MoveNext() is made.
  • MoveNext() must make all computations to generate the next element. In general, a private variable holds the current value, is calculated in this method, and returned by Current.
  • Generators that are built from other generators must CloneAndRestart() the generators and store the clones. This ensures calls to MoveNext() in this generator won't affect elements generated by a generated passed in as an argument in the constructor.
  • The generator must store all information needed to be able to produce an equivalent generator in CloneAndRestart(). Generally, generators are equivalent when they generate the same elements (in the same order). There are some exceptions, for example, unseeded random number generators. It is not necessary to CloneAndRestart() generators stored internally when creating a new instance of the generator, since that should be done in the constructor.

Properties

Current

Gets the element last generated by this generator.

Methods

CloneAndRestart()

Clones the generator and returns the clone in a restarted state.