List Comprehension equivalent

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 17 12:08:36 PDT 2017


On Fri, 2017-03-17 at 17:51 +0000, 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!debianPackageNumberComparator()[0..$-1].array;
> > 	}
> > 	return returnValue;
> > 
> > [...]
> 
> You forgot a ! on the map call.
> 
> .map!((Tuple!(string, string[]) a) => 
> a[1].sort!debianPackageNumberComparator()[0..$-1])

How embarrassed am I? :-)

However, the result of the map appears to be untransformable to
anything related to a sequence of string. The result is some type that
renders as a sequence of sequence using writeln but how to reduce it to
a sequence? reduce isn't defined on MapResult and if I transform to an
array reduce is not defined on SortedRange[]. Rust ownership problems
seem to be a doddle compared to this problem.
 
-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20170317/e6ecd30c/attachment.sig>


More information about the Digitalmars-d-learn mailing list