Created
March 28, 2020 22:47
-
-
Save TheFo2sh/dcf7531ece92fcecae960d958021cf33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GeneratorEnumerator<T> : IEnumerator<T> | |
{ | |
private readonly Func<int,T> _generatorFunc; | |
private int _index; | |
private T _current; | |
public GeneratorEnumerator(Func<int, T> generatorFunc) | |
{ | |
_generatorFunc = generatorFunc; | |
} | |
public bool MoveNext() | |
{ | |
_current = _generatorFunc(_index++); | |
return true; | |
} | |
public void Reset() | |
{ | |
_current = default(T); | |
_index = 0; | |
} | |
public T Current => _current; | |
object IEnumerator.Current => Current; | |
public void Dispose() | |
{ | |
_current = default(T); | |
_index = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment