Creating immutable arrays in @safe code

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jul 16 20:45:11 UTC 2021


On Fri, Jul 16, 2021 at 08:19:32PM +0000, Dennis via Digitalmars-d-learn wrote:
[...]
> ```D
> immutable(int)[] positive(int[] input) @safe
> {
>     return input.filter!(x => x > 0).array;
> }
> ```
[...]
> I could make another primitive (`iarraySort`), but I wonder if there
> are more convenient ways to create immutable data in general?

Have you tried `pure`?


T

-- 
They say that "guns don't kill people, people kill people." Well I think the gun helps. If you just stood there and yelled BANG, I don't think you'd kill too many people. -- Eddie Izzard, Dressed to Kill


More information about the Digitalmars-d-learn mailing list