Passing function(whose parameter would be dynamic and the type is unknown) as a parameter to another function.

Timoses timosesu at gmail.com
Tue Jul 10 15:17:35 UTC 2018


On Tuesday, 10 July 2018 at 14:58:42 UTC, vino.B wrote:

> Hi Alex,
>
>  I am getting the output as tuples of multiple arrays, but the 
> requirement is to get the all the tuple in a single array like 
> the below so that we can perform sorting and printing the 
> output is easy.

Something along the way

     unittest
     {
         import std.typecons : Tuple, tuple;
	alias pair = Tuple!(string, int);

         pair[] values;
         values ~= tuple("du", 7);
         values ~= tuple("Vino", 3);
         values ~= tuple(",", 4);
         values ~= tuple("hur", 5);
         values ~= tuple("Hej", 2);
         values ~= tuple("?", 8);
         values ~= tuple("mår", 6);

         import std.algorithm : sort, each;
         import std.stdio : write;
         values.sort!((p1, p2) => p1[1] < p2[1])
               .each!(p => write(p[0] ~ " "));
     }

?



More information about the Digitalmars-d-learn mailing list