Re: Learning to use ranges instead of arrays

2014-07-21 Thread John Colvin via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:02:05 UTC, Bob Tolbert wrote: I find myself writing this code too much and i'm curious what D idiom I am missing. given a list of files (or any strings) and then maybe I want to sort them and maybe I don't. string [] fileList; ... fill list if

Re: Learning to use ranges instead of arrays

2014-07-21 Thread Bob Tolbert via Digitalmars-d-learn
On Sunday, 20 July 2014 at 16:11:03 UTC, John Colvin wrote: Even without ranges, you can do this: string [] fileList; ... fill list if (sort) sort(fileList); foreach(filename, fileList) { ... do something; } because sort works in-place.

Re: Learning to use ranges instead of arrays

2014-07-21 Thread Bob Tolbert via Digitalmars-d-learn
Sorry, somehow this submitted in the middle, even without the captcha. Please see the later version.

Re: Learning to use ranges instead of arrays

2014-07-21 Thread Ivan Kazmenko via Digitalmars-d-learn
Also, there is std.array.array for the ranges you want to convert to arrays. For example, if a is an array, a.map!(x = x * 2).array produces an new array of doubled values (as opposed to a lazy range produced by std.algorithm.map).