Issue Details (XML | Word | Printable)

Key: BOO-366
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Rodrigo B. de Oliveira
Reporter: Rodrigo B. de Oliveira
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Remove one level of indirection from generators and allow generator methods to use IEnumerator as the return type

Created: 22/Jun/05 09:15 AM   Updated: 22/Sep/05 02:50 PM
Component/s: Compiler
Affects Version/s: 0.5
Fix Version/s: 0.7

Time Tracking:
Not Specified


 Description  « Hide
Today is not possible to use yield to implement IEnumerable.GetEnumerator() because generators must be declared as returning IEnumerable.

Another problem is that we always have one level of indirection from the enumerator which makes very hard to consume a generator() incrementally like:

generator = { yield 1; yield 2 }
e = generator()
item, = e
assert 1 == item
item, = e
assert 2 == item

  1. generator exhausted here


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Sorin Ionescu added a comment - 07/Aug/05 10:26 PM
Please cast the generators to the interface in question before you return them.
Seeing __________generator1 is not pretty; we shouldn't have to type "GetEnumerator() as IEnumerator" to get around that.

Rodrigo B. de Oliveira added a comment - 08/Aug/05 04:33 AM
If the method in question belongs to an implemented interface its return type will be preserved.

The anonymous types are necessary to preserve type informaiton.


Rodrigo B. de Oliveira added a comment - 22/Sep/05 02:50 PM
I didn't remove the level of indirection but simply allowed generator methods to declare their return type as IEnumerator directly. This has the advantage of not breaking any code while still allowing to easily implement IEnumerable.GetEnumerator.