Thread overview
std.array.array for immutable data types
Feb 19, 2018
Fra Mecca
Feb 19, 2018
Seb
Feb 19, 2018
Nicholas Wilson
Feb 19, 2018
Jonathan M Davis
February 19, 2018
Is there a way to avoid using to! conversion here?

immutable string[] dst = to!(immutable string[])(array(pipe.readEnd.byLineCopy));

February 19, 2018
On Monday, 19 February 2018 at 07:08:49 UTC, Fra Mecca wrote:
> Is there a way to avoid using to! conversion here?
>
> immutable string[] dst = to!(immutable string[])(array(pipe.readEnd.byLineCopy));

Are you looking for something like assumeUnique [1]?

```
pipe.readEnd.byLineCopy.array.assumeUnique;
```

It's just a nice wrapper for cast(immutable string[]).


[1] https://dlang.org/phobos/std_exception.html#assumeUnique
February 19, 2018
On Monday, 19 February 2018 at 07:08:49 UTC, Fra Mecca wrote:
> Is there a way to avoid using to! conversion here?
>
> immutable string[] dst = to!(immutable string[])(array(pipe.readEnd.byLineCopy));

assumeUnique.

immutable string[] dst = pipe.readEnd.byLineCopy.array.assumeUnique;
February 19, 2018
On Monday, February 19, 2018 07:25:07 Nicholas Wilson via Digitalmars-d- learn wrote:
> On Monday, 19 February 2018 at 07:08:49 UTC, Fra Mecca wrote:
> > Is there a way to avoid using to! conversion here?
> >
> > immutable string[] dst = to!(immutable
> > string[])(array(pipe.readEnd.byLineCopy));
>
> assumeUnique.
>
> immutable string[] dst = pipe.readEnd.byLineCopy.array.assumeUnique;

Arguably, to!(immutable string[]) should work on the result of byLineCopy, but it doesn't seem to. If it did, then that would eliminate the need for assumeUnique, and it's always better to avoid assumeUnique if you can. However, given the current limitation with to and byLineCopy, it probably is the best solution.

- Jonathan M Davis