Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is actually really convenient.

In our code we have an abstraction that wraps a set using a variant. Instead of implementing an iterator/begin/end based on which data the variant holds, we have an iter() method that unwraps the variant and loops through and co_yields. Since you can consume a generator in a for-each loop, you use it the exact same way (except calling iter).

In our case it doesn't save that much complexity, but it's definitely some. I could imagine more complicated cases where it is even more convenient.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: