Practice ยท 2 of 3
Deferred, Not Cached
CHALLENGE
Difficulty: intermediate+25 XP
Double is an iterator over a counting source. Implement Double(IEnumerable<int>) (each value ร2) and RunOnce(IEnumerable<int>) that materializes the doubled values with ONE pass over the source. The tests prove the source is pulled only when enumerated โ and only once.
``csharp
public sealed class CountingSource : IEnumerable<int> // provided by tests
{
public int ReadCount { get; } // items actually pulled
}
static IEnumerable<int> Double(IEnumerable<int> source);
static List<int> RunOnce(IEnumerable<int> source); // exactly one pass
``
Press Submit to check your solution.
Back to lesson: Practice: Iterators & Pipelines Practice