On Saturday, 9 December 2017 at 03:24:52 UTC, codephantom wrote:
On Saturday, 9 December 2017 at 02:45:35 UTC, rjframe wrote:

`sort` returns a SortedRange of ushorts, not an array of ushorts. Make it:

```
import std.array : array;
return sort(numbers.take(8)).array;
```

--Ryan

That's it!

Thanks Ryan.

You can also return a lazy range:

```
auto draw8Numbers()
{
     import std.meta : aliasSeqOf;
     import std.range : iota, take;
     ushort[] numbers = [ aliasSeqOf!(iota(1,46)) ];
     import std.random : randomShuffle;
     randomShuffle(numbers);
     import std.algorithm.sorting : sort;
     return sort(numbers[].take(8));
}

void main()
{
    import std.array;
ushort[] nbrs = draw8Numbers.array; // evaluated after return, during assingment
}
```

Reply via email to