Thread overview | |||||
---|---|---|---|---|---|
|
July 04, 2017 How to get uniq to return an array? | ||||
---|---|---|---|---|
| ||||
I'm trying to strip repeated values out of an int array using uniq. It's returning a UniqResult which can't be accessed like an array... how can I get it to return an array, or cast whatever it is returning to be an array? |
July 04, 2017 Re: How to get uniq to return an array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to PumpkinCake | On Tuesday, 4 July 2017 at 11:00:05 UTC, PumpkinCake wrote:
> I'm trying to strip repeated values out of an int array using uniq. It's returning a UniqResult which can't be accessed like an array... how can I get it to return an array, or cast whatever it is returning to be an array?
Most functions are lazy in order to allow more centrol over the memory. This means the actual value is computed only when needed.
To use an array import std.array and do [1, 1, 2].uniq.array; for example. This will allocate a new array to keep the result.
|
July 04, 2017 Re: How to get uniq to return an array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to PumpkinCake Attachments:
| have you tried std.range's .array? 2017-07-04 13:00 GMT+02:00 PumpkinCake via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>: > I'm trying to strip repeated values out of an int array using uniq. It's returning a UniqResult which can't be accessed like an array... how can I get it to return an array, or cast whatever it is returning to be an array? > |
Copyright © 1999-2021 by the D Language Foundation