Re: How to store unique values of array in another array

2018-10-18 Thread Samir via Digitalmars-d-learn

On Thursday, 18 October 2018 at 19:25:26 UTC, Adam D. Ruppe wrote:

Which is better simply depends on which one reads better to you.


Thanks again, Adam.


Re: How to store unique values of array in another array

2018-10-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 18 October 2018 at 19:19:53 UTC, Samir wrote:

They both seem to work.  Is one preferred over the other?


No difference. The compile will just transform o.f into f(o) if 
it can. They both do the same thing and it is just a different 
way of writing it.


Which is better simply depends on which one reads better to you.


Re: How to store unique values of array in another array

2018-10-18 Thread Samir via Digitalmars-d-learn

On Thursday, 18 October 2018 at 18:53:06 UTC, Adam D. Ruppe wrote:
But, if you need to copy it into a new array, use `.array` at 
the end.


Thanks.  That did the trick.  But if I may, what is the 
difference between


uniqueArray = uniq(sort(unsortedArray)).array;

and

uniqueArray = unsortedArray.sort().uniq.array;

They both seem to work.  Is one preferred over the other?



Re: How to store unique values of array in another array

2018-10-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 18 October 2018 at 18:39:18 UTC, Samir wrote:
which leads me to believe that the output of `uniq` is not 
necessarily another integer array.


Right, it is actually a "range" - an object that generates the 
result on-demand, so it doesn't do work you don't actually need. 
If you don't need an array per se, you can just foreach over it 
and print them or further work on it without the cost of creating 
a new array.


But, if you need to copy it into a new array, use `.array` at the 
end.