From the course: C#: Design Patterns Part 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Simultaneous iterators

Solution: Simultaneous iterators - Python Tutorial

From the course: C#: Design Patterns Part 1

Start my 1-month free trial

Solution: Simultaneous iterators

(upbeat music) - [Instructor] There are a number of ways to solve this. I went with the most generic and reusable way that I could think of, but it may not be the best choice for every situation. First, in the core project, I added an extension. This method takes an enumerable to iterate through, a filter expression to reduce what returns, and a function to transform the input type. In this case, to select the date field that I'm looking for. It returns an enumerable of whatever result type that returns from that expression. The logic is simple. It iterates through a list. If the expression is true, run the transformation action that was specified. There is a bit of iterator magic here in the yield return. This is what's making this method return an enumerable. Yield means return control back to the caller. Whatever code is using this enumeration will execute the code that it has planned. And the next execution of this…

Contents