[swift-evolution] Proposal: Add generator functions to the language

Andrey Tarantsov andrey at tarantsov.com
Fri Dec 11 20:14:07 CST 2015


> I think you need some explicit marker. Consider the following:
> 
>    func f() -> Int {
>        return
>    }
> 
> Is this (1) a generator that returns without yielding anything, or (2) an ordinary function that incorrectly fails to return a value?

Perhaps that's too much magic, and generator functions should explicitly declare the return type of GeneratorType<Xxx>. Being a generator is an implementation detail, after all.

Also, I'm not sure than a statically empty generator function is a useful concept. You could just say that without a yield, it's not a generator, period.

A.



More information about the swift-evolution mailing list