Array merge and sort
Jordan Wilson
wilsonjord at gmail.com
Wed Sep 20 09:26:25 UTC 2017
On Wednesday, 20 September 2017 at 06:29:17 UTC, Vino.B wrote:
> Hi All,
>
> My code output's the below so can any one help me on hot to
> merege all tese array and sort the same.
>
> Output :
> [ Tuple!(string, string)("C:\\Temp\\TEST1\\BACKUP\\DND1.pdf",
> "2017-Sep-06 16:06:42") ]
> [ Tuple!(string, string)("C:\\Temp\\TEST2\\EXPORT\\DND1.pdf",
> "2017-Sep-06 16:06:43")]
> [ Tuple!(string,
> string)("C:\\Temp\\TEST3\\PROD_TEAM\\DND1.pdf", "2017-Sep-06
> 16:06:43")]
> [ Tuple!(string, string)("C:\\Temp\\TEST4\\TEAM\\DND1.pdf",
> "2017-Sep-06 16:06:44") ]
>
> Code :
> foreach (string FFs; parallel(CleanDirlst[0 .. $], 1)) {
> MCresult.get ~= coCleanFiles(FFs.strip, Step);
> }
> foreach(i; MCresult.toRange)
> if (!i.empty) { writefln("%(%-(%-63s %s %)\n%)", i[]); }
>
>
> From,
> Vino.B
I'm not sure what MCresult is, but perhaps using joiner can help
you.
import std.algorithm : joiner, sort;
import std.range : array;
import std.typecons : Tuple;
auto data = [[Tuple!(string,string)("test4","1")],
[Tuple!(string,string)("test3","4"),Tuple!(string,string)("test2","3")],
[Tuple!(string,string)("test1","2")]];
auto sortedData = data.joiner
.array
.sort!((a,b) => a[0] < b[0]);
sortedData.writeln;
// outputs
// [Tuple!(string, string)("test1", "2"), Tuple!(string,
string)("test2", "3"), Tuple!(string, string)("test3", "4"),
Tuple!(string, string)("test4", "1")]
Jordan
More information about the Digitalmars-d-learn
mailing list