Archive

Posts Tagged ‘iterators’

Making Lambdas and Iterators Play Nicely Together

February 26, 2009 Leave a comment

The major problem with this idea is in my favourite feature of C#. In an iterator (a function containing the yield keyword), the code is transformed into a state machine represented by a class. It has to be chopped up into sections, so the function can be “paused” after each yield return. Those pieces must all be in the same function, so sadly lambdas don’t play well with iterators.

There are a couple of possible future language features which would completely solve this, however.

Read more…

Categories: C#, lambdas, yield return Tags: , ,