Re: Functional Sort

2014-11-15 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 03:47:25 UTC, Steven Schveighoffer wrote: err... this isn't what you want. That will sort the range, and then make a copy of the sorted range as an array. Yes, I didn't see the the second constraint to not sort the original range. Sort before .array -

Re: Functional Sort

2014-11-15 Thread Nordlöw
On Saturday, 15 November 2014 at 03:47:25 UTC, Steven Schveighoffer wrote: Note, there isn't any generic way to say give me a copy of this range, as the same type. array is probably the best you will get. Just make sure you call it *before* you sort, unless you want both ranges sorted :)

Re: Functional Sort

2014-11-15 Thread Nordlöw
On Saturday, 15 November 2014 at 08:52:45 UTC, Meta wrote: On Saturday, 15 November 2014 at 03:47:25 UTC, Steven Schveighoffer wrote: err... this isn't what you want. That will sort the range, and then make a copy of the sorted range as an array. Yes, I didn't see the the second constraint to

Re: Functional Sort

2014-11-15 Thread Nordlöw
On Saturday, 15 November 2014 at 14:34:07 UTC, Nordlöw wrote: What's wrong with my isArray-overload of sorted? I solved it by replacing R s = r.dup; with auto s = r.dup; As a follow up I know wonder if it is ok for isArray-overload of sorted() to have return type ubyte[] if input

Re: Functional Sort

2014-11-14 Thread Nordlöw
On Saturday, 15 November 2014 at 00:45:11 UTC, Meta wrote: `sort` returns a SortedRange, so sort is the function you're looking for. Do you mean std.algorithm.sort? I want a sort that doesn't mutate its input argument.

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 00:33:11 UTC, Nordlöw wrote: Is there a functional variant of std.algorithm.sort, say sorted, that returns a sorted copy of its input use typically as const y = x.sorted; ? If not any recommendations on its implementation? `sort` returns a SortedRange,

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 00:45:11 UTC, Meta wrote: On Saturday, 15 November 2014 at 00:33:11 UTC, Nordlöw wrote: Is there a functional variant of std.algorithm.sort, say sorted, that returns a sorted copy of its input use typically as const y = x.sorted; ? If not any

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 00:47:41 UTC, Nordlöw wrote: On Saturday, 15 November 2014 at 00:45:11 UTC, Meta wrote: `sort` returns a SortedRange, so sort is the function you're looking for. Do you mean std.algorithm.sort? I want a sort that doesn't mutate its input argument. In that

Re: Functional Sort

2014-11-14 Thread Nordlöw
On Saturday, 15 November 2014 at 00:47:57 UTC, Meta wrote: `sort` returns a SortedRange, so sort is the function you're looking for. Sorry, and if you want a copy, just add a `.array` on the end to create a new array from the returned range. Great! Should I use std.algorithm.array or

Re: Functional Sort

2014-11-14 Thread Meta via Digitalmars-d-learn
On Saturday, 15 November 2014 at 01:01:57 UTC, Nordlöw wrote: On Saturday, 15 November 2014 at 00:47:57 UTC, Meta wrote: `sort` returns a SortedRange, so sort is the function you're looking for. Sorry, and if you want a copy, just add a `.array` on the end to create a new array from the

Re: Functional Sort

2014-11-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/14/14 7:47 PM, Meta wrote: On Saturday, 15 November 2014 at 00:45:11 UTC, Meta wrote: On Saturday, 15 November 2014 at 00:33:11 UTC, Nordlöw wrote: Is there a functional variant of std.algorithm.sort, say sorted, that returns a sorted copy of its input use typically as const y =