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); } static if(is(typeof(range.save))) @property auto save(){ return Map!(fun, R)(range.save); } ... }