Tuple DIP
Nick Treleaven
nick at geany.org
Thu Mar 15 13:42:56 UTC 2018
On Wednesday, 17 January 2018 at 06:44:21 UTC, Timon Gehr wrote:
> It uses tuples because it uses zip. The code does not compile
> today, because the lambda I'm passing to "map" has two
> parameters:
>
> auto a = [1, 2, 4, 7, 2];
> auto b = [3, 5, 3, 2, 4];
>
> // auto c = zip(a, b).map!((x, y) => x + y); // error
>
> auto c = zip(a, b).map!(t => t[0] + t[1]); // ok
We could make lambdas consistent with proposal 5:
// Proposal 5: Unpacking function arguments
void foo((int x, int y), int z){
writeln(x, " ", y, " ", z);
}
// lambda takes one tuple of two elements
alias f = ((x, y)) => x + y;
auto c = zip(a, b).map!f; // ok
Is there a better example as to why a tuple decaying to function
arguments is worth having vs the language complication?
More information about the Digitalmars-d
mailing list