yield iteration

Timon Gehr timon.gehr at gmx.ch
Sun Jul 29 07:49:05 PDT 2012


On 07/29/2012 04:48 PM, Timon Gehr wrote:
> Ideally it would look like this:
>
> struct Map(alias fun, R){
>      R range;
>      mixin YieldInputRange!q{
>          for(; !range.empty; range.popFront())
>              yield fun(range.front);
>      }
>      static if(is(typeof(range.save))) @property auto save(){
>          return Map!(fun, R)(range.save);
>      }
>      ...
> }
>
> Or as a built-in:
>
> struct Map(alias fun, R){
>      R range;
>      yield {
>          for(; !range.empty; range.popFront())
>              yield fun(x);
                yield fun(range.front); // oops
>      }
>      static if(is(typeof(range.save))) @property auto save(){
>          return Map!(fun, R)(range.save);
>      }
>      ...
> }



More information about the Digitalmars-d mailing list