List Comprehension equivalent

2017-03-17 Thread Russel Winder via Digitalmars-d-learn
I have a bit of code: string[] returnValue; foreach(string key, string[] value; groups) { returnValue ~= value.sort!debianPackageNumberComparator()[0..$-1].array; } return returnValue; which does seem to do the thing required, but this sort of code

Re: List Comprehension equivalent

2017-03-17 Thread Jerry via Digitalmars-d-learn
On Friday, 17 March 2017 at 17:13:48 UTC, Russel Winder wrote: I have a bit of code: string[] returnValue; foreach(string key, string[] value; groups) { returnValue ~= value.sort!debianPackageNumberComparator()[0..$-1].array; } return returnValue; [...] You

Re: List Comprehension equivalent

2017-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 03/17/2017 10:51 AM, Jerry wrote: On Friday, 17 March 2017 at 17:13:48 UTC, Russel Winder wrote: I have a bit of code: string[] returnValue; foreach(string key, string[] value; groups) { returnValue ~= value.sort!debianPackageNumberComparator()[0..$-1].array; } return

Re: List Comprehension equivalent

2017-03-17 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2017-03-17 at 17:51 +, Jerry via Digitalmars-d-learn wrote: > On Friday, 17 March 2017 at 17:13:48 UTC, Russel Winder wrote: > > I have a bit of code: > > > > string[] returnValue; > > foreach(string key, string[] value; groups) { > > returnValue ~=  > > value.sort!

Re: List Comprehension equivalent

2017-03-17 Thread John Colvin via Digitalmars-d-learn
On Friday, 17 March 2017 at 19:08:36 UTC, Russel Winder wrote: On Fri, 2017-03-17 at 17:51 +, Jerry via Digitalmars-d-learn wrote: On Friday, 17 March 2017 at 17:13:48 UTC, Russel Winder wrote: > I have a bit of code: > > string[] returnValue; >foreach(string key, string[] value; grou

Re: List Comprehension equivalent

2017-03-17 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2017-03-17 at 19:21 +, John Colvin via Digitalmars-d-learn wrote: > […] > > reduce is a free function in std.algorithm. Just import it and  > you're away. Anyway, is this what you wanted? > > string[] blah(string[][string] groups) > { >  import std.algorithm : map, joiner; >  

Re: List Comprehension equivalent

2017-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 03/17/2017 12:21 PM, John Colvin wrote: > On Friday, 17 March 2017 at 19:08:36 UTC, Russel Winder wrote: >> Rust ownership problems >> seem to be a doddle compared to this problem. It sometimes feels like that but we don't want to lose you. :) > reduce is a free function in std.algorithm. Ju

Re: List Comprehension equivalent

2017-03-17 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 17, 2017 at 07:21:50PM +, John Colvin via Digitalmars-d-learn wrote: [...] > reduce is a free function in std.algorithm. Just import it and you're > away. [...] Also, there is now a variant of reduce called `fold`, that has a nicer order of parameters, i.e., you can use it in UFCS

Re: List Comprehension equivalent

2017-03-18 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2017-03-17 at 12:29 -0700, H. S. Teoh via Digitalmars-d-learn wrote: > […] > Also, there is now a variant of reduce called `fold`, that has a > nicer > order of parameters, i.e., you can use it in UFCS chains: > > myData.map!(a => transform(a)) >   .fold!((a,b) => a + b)(0

Re: List Comprehension equivalent

2017-03-18 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2017-03-17 at 12:32 -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 03/17/2017 12:21 PM, John Colvin wrote: >  > On Friday, 17 March 2017 at 19:08:36 UTC, Russel Winder wrote: > >  >> Rust ownership problems >  >> seem to be a doddle compared to this problem. > > It sometimes feels

Re: List Comprehension equivalent

2017-03-18 Thread thedeemon via Digitalmars-d-learn
On Saturday, 18 March 2017 at 11:09:34 UTC, Russel Winder wrote: Is this foldr or foldl' ? It's a left fold of course, having foldr by default in eager language would be awkward.

Re: List Comprehension equivalent

2017-03-18 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2017-03-18 at 11:38 +, thedeemon via Digitalmars-d-learn wrote: > On Saturday, 18 March 2017 at 11:09:34 UTC, Russel Winder wrote: > > Is this foldr or foldl' ? > > It's a left fold of course, having foldr by default in eager  > language would be awkward. I would expect foldl, but the