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 ContinuationIncrementer : IEnumerable<int> | |
| { | |
| public IEnumerator<int> GetEnumerator() | |
| { | |
| int n = 0; | |
| while (true) | |
| { | |
| yield return ++n; | |
| } | |
| } |
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
| foreach (int i in new Incrementer()) | |
| { | |
| Console.WriteLine(i); | |
| if (i == 10) { break; } | |
| } |
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 NumberSequence : IEnumerable<int> | |
| { | |
| private readonly int _startValue; | |
| private readonly int _increment; | |
| public NumberSequence(int startValue, int increment) | |
| { | |
| _startValue = startValue; | |
| _increment = increment; | |
| } |
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 BrokenRecord<T> : IEnumerable<T> | |
| { | |
| private readonly IEnumerable<T> _seq; | |
| public BrokenRecord(IEnumerable<T> seq) | |
| { | |
| _seq = seq; | |
| } | |
| public IEnumerator<T> GetEnumerator() |
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
| var words = new [] { "Hello", "dear", "friend" }; | |
| int wordCount = 0; | |
| foreach (string s in new BrokenRecord(words)) | |
| { | |
| Console.WriteLine(s); | |
| if (++wordCount == 10) { break; } | |
| } |
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 PrimeSequence : IEnumerable<int> | |
| { | |
| public IEnumerator<int> GetEnumerator() | |
| { | |
| return new SimplePrimeEnumerator(); | |
| } | |
| IEnumerator IEnumerable.GetEnumerator() | |
| { | |
| return GetEnumerator(); |
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 PrimeSequence : IEnumerable<int> | |
| { | |
| public IEnumerator<int> GetEnumerator() | |
| { | |
| yield return 2; | |
| var e = new OddPrimeEnumerator(); | |
| while (e.MoveNext()) | |
| { | |
| yield return e.Current; | |
| } |
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 OddPrimeEnumerator : IEnumerator<int> | |
| { | |
| private readonly IEnumerator<int> _candidates = | |
| new NumberEnumerator(3, 2); | |
| private readonly IPriorityQueue<NumberEnumerator> _pq = | |
| new IntervalHeap<NumberEnumerator>(); | |
| public int Current | |
| { | |
| get { return _candidates.Current; } |
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 WheelSequence : IEnumerable<int> | |
| { | |
| private readonly int _startValue; | |
| private readonly IEnumerable<int> _; | |
| public WheelSequence(int startValue, | |
| IEnumerable<int> skipSequence) | |
| { | |
| _startValue = startValue; | |
| _ = skipSequence; |
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
| var skip = new[] { 4, 2, 4, 2, 4, 6, 2, 6 }; | |
| var skipSequence = new BrokenRecord<int>(skip); |