Can't we simply use map, so as not to introduce new syntax?

import std.algorithm:map;
import std.array:array;

// some imports here
void main() {
    //BigInt[] data1 = [5, 6, 9];
    auto data1 = [5, 6, 9].map!(a=>BigInt(a)).array;
    Ranged!(int,5,10)[] data2 = [5, 6, 9];
    auto data2 = [5, 6, 9].map!(a=>Ranged!(int,5,10)).array;
}

I think this is less verbose than something like:
AStruct[] arr = mixin(structArray!AStruct("1,1", "1,2", "2,2", "2,3"));

Also, we can make it even more concise by:
auto data1 = [5, 6, 9].map!(make!BigInt).array; //make has been proposed as a proxy to construct a struct/class

or even the very concise:
auto data1 = [5, 6, 9].mapMake!BigInt;

where mapMake would be similar to std.algorithm.map except it would take a struct (or class) type instead of a delegate. It's code should be fairly obvious. We could choose whether to return a lazy range or not in that case so the ".array" is not required.


Reply via email to