| « Creating a Lazy Sequence of Directory Descendants in F# | Google's precision is getting worse » |
The yield statement cannot be used inside an anonymous method or lambda expression
09/03/10
The yield statement cannot be used inside an anonymous method or lambda expression
I thought I was being pretty cool with this code:
IEnumerator<t> System.Collections.Generic.IEnumerable<t>.GetEnumerator( ) {
Action<unbalancedbinarytree <T>> yielder = null;
yielder = t => {
yielder(t.Left);
if (!t.IsEmpty)
yield return t.Value;
yielder(t.Right);
};
yielder(this);
}
But as it turns out (and I think I knew before, but had forgotten), C# doesn’t accept this. Not in 3.0 at least, and I think not in 4.0 either. Need to test. Meanwhile – why? Hm…
3 comments
Comment from: Peter Ritchie [Visitor]
03/09/10 @ 19:43
Comment from: Igor Dontsov [Visitor]
03/09/10 @ 22:16
Thanks for the link. Yeah... sounds a bit like "we don't really think it's quite that useful and we're scared of getting it wrong" :-) Legitimate reasons I guess, but still a pity.
03/09/10 @ 22:30


