Thread overview
Container Array or tuples Sorting
Dec 13
Vino
Dec 13
Vino
Dec 13
Vino
December 13
Hi All,

 Request your help, on how to sort a tuple container array, I have raised the same topic in one of the other thread "Tuple Array Sorting" and was addressed to use standard array rather than container array, and i am not able to find any document or example in the library for the same.

Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir)
	.sort!((a,b) => a.timeCreated > b.timeCreated)
	.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B

December 13
On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:
> Hi All,
>
>  Request your help, on how to sort a tuple container array, I have raised the same topic in one of the other thread "Tuple Array Sorting" and was addressed to use standard array rather than container array, and i am not able to find any document or example in the library for the same.
>
> Eg: Program.
> import std.algorithm: filter, map, sort;
> import std.container.array;
> import std.file: SpanMode, dirEntries, isDir ;
> import std.stdio: writeln;
> import std.typecons: Tuple, tuple;
> import std.datetime.systime: SysTime;
>
> void main () {
> auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
> Array!(Tuple!(string, SysTime)) Result;
> foreach(d; FFs[]) {
> auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir)
> 	.sort!((a,b) => a.timeCreated > b.timeCreated)
> 	.map!(a => tuple(a.name, a.timeCreated)));
> writeln(dFiles[]);
> } }
>
> From,
> Vino.B

HI All,

  As per the message from the below forum  I understand that that we cannot perform a sorting on filtered result a container array but the same can be performed form the standard array, so i adjusted the above code as below and getting a different error than what is discussed in the forum.

Forum:
 "https://forum.dlang.org/post/mcteinnryudlqvbkqttz@forum.dlang.org"

Program:
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", "C:\\Temp\\sapnas2\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, a.timeCreated)))[]
	.sort!((a,b) => a[1] > b[1]);
writeln(dFiles[]);
} }

Error:
Message.d(14): Error: function Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is not callab
le using argument types ()
Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]

From,
Vino.B
December 13
On Wednesday, 13 December 2017 at 15:58:40 UTC, Vino wrote:
> On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:
>> Hi All,
>>
>>  Request your help, on how to sort a tuple container array, I have raised the same topic in one of the other thread "Tuple Array Sorting" and was addressed to use standard array rather than container array, and i am not able to find any document or example in the library for the same.
>>
>> Eg: Program.
>> import std.algorithm: filter, map, sort;
>> import std.container.array;
>> import std.file: SpanMode, dirEntries, isDir ;
>> import std.stdio: writeln;
>> import std.typecons: Tuple, tuple;
>> import std.datetime.systime: SysTime;
>>
>> void main () {
>> auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
>> Array!(Tuple!(string, SysTime)) Result;
>> foreach(d; FFs[]) {
>> auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir)
>> 	.sort!((a,b) => a.timeCreated > b.timeCreated)
>> 	.map!(a => tuple(a.name, a.timeCreated)));
>> writeln(dFiles[]);
>> } }
>>
>> From,
>> Vino.B
>
> HI All,
>
>   As per the message from the below forum  I understand that that we cannot perform a sorting on filtered result a container array but the same can be performed form the standard array, so i adjusted the above code as below and getting a different error than what is discussed in the forum.
>
> Forum:
>  "https://forum.dlang.org/post/mcteinnryudlqvbkqttz@forum.dlang.org"
>
> Program:
> void main () {
> auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", "C:\\Temp\\sapnas2\\EXPORT"];
> Array!(Tuple!(string, SysTime)) Result;
> foreach(d; FFs[]) {
> auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, a.timeCreated)))[]
> 	.sort!((a,b) => a[1] > b[1]);
> writeln(dFiles[]);
> } }
>
> Error:
> Message.d(14): Error: function Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is not callab
> le using argument types ()
> Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]
>
> From,
> Vino.B

Hi All,

 Was able to find a solution and it is working as expected

import std.algorithm: filter, map, sort, each;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
import std.conv;
void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, a.timeCreated)));
foreach(i; dFiles[]){ Sorted ~= i; }
Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s %.20s"(e[0], e[1].to!string));
}
}

From,
Vino.B