Thread overview
Getting the underlying range from std.range.indexed, with elements in swapped order, when Indexed.source.length == Indexed.indices.length
Jun 27, 2018
Uknown
Jun 27, 2018
Alex
Jun 27, 2018
Uknown
Jun 27, 2018
Alex
Jun 27, 2018
Uknown
Jun 27, 2018
Alex
Jun 27, 2018
Uknown
June 27, 2018
Title says it all. Is there a trivial way to do this?
June 27, 2018
On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote:
> Title says it all. Is there a trivial way to do this?

There are
https://dlang.org/library/std/algorithm/mutation/reverse.html
and
https://dlang.org/library/std/range/retro.html

both require a bidirectional range, which Indexed, luckily is.
June 27, 2018
On Wednesday, 27 June 2018 at 14:21:39 UTC, Alex wrote:
> On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote:
>> Title says it all. Is there a trivial way to do this?
>
> There are
> https://dlang.org/library/std/algorithm/mutation/reverse.html
> and
> https://dlang.org/library/std/range/retro.html
>
> both require a bidirectional range, which Indexed, luckily is.

I wasn't clear enough. I meant getting back the underlying `Source` range with _its_ elements in the order that the indices specify. This wouldn't be possible in the generic case, but the special case when indices.length == source.length, it should be possible. So indexed(myRange, [2, 3, 5, 1, 4]).sourceWithSwappedElements should return a typeof(myRange) with the elements swapped in that order.
June 27, 2018
On Wednesday, 27 June 2018 at 14:29:33 UTC, Uknown wrote:
> On Wednesday, 27 June 2018 at 14:21:39 UTC, Alex wrote:
>> On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote:
>>> Title says it all. Is there a trivial way to do this?
>>
>> There are
>> https://dlang.org/library/std/algorithm/mutation/reverse.html
>> and
>> https://dlang.org/library/std/range/retro.html
>>
>> both require a bidirectional range, which Indexed, luckily is.
>
> I wasn't clear enough. I meant getting back the underlying `Source` range with _its_ elements in the order that the indices specify. This wouldn't be possible in the generic case, but the special case when indices.length == source.length, it should be possible. So indexed(myRange, [2, 3, 5, 1, 4]).sourceWithSwappedElements should return a typeof(myRange) with the elements swapped in that order.

I see. Ok, one possibility is

source = indexed(source, indices).array;

but I assume you want something without extra allocation, right?
June 27, 2018
On Wednesday, 27 June 2018 at 14:50:25 UTC, Alex wrote:
> On Wednesday, 27 June 2018 at 14:29:33 UTC, Uknown wrote:
>> On Wednesday, 27 June 2018 at 14:21:39 UTC, Alex wrote:
>>> On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote:
>>>> [...]
>
> I see. Ok, one possibility is
>
> source = indexed(source, indices).array;
>
> but I assume you want something without extra allocation, right?

This doesn't work for some reason.

"123".byCodeUnit.permutations.array.writeln //[123, 123, 123, 123, 123, 123]
June 27, 2018
On Wednesday, 27 June 2018 at 15:07:57 UTC, Uknown wrote:
> On Wednesday, 27 June 2018 at 14:50:25 UTC, Alex wrote:
>> On Wednesday, 27 June 2018 at 14:29:33 UTC, Uknown wrote:
>>> On Wednesday, 27 June 2018 at 14:21:39 UTC, Alex wrote:
>>>> On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote:
>>>>> [...]
>>
>> I see. Ok, one possibility is
>>
>> source = indexed(source, indices).array;
>>
>> but I assume you want something without extra allocation, right?
>
> This doesn't work for some reason.
>
> "123".byCodeUnit.permutations.array.writeln //[123, 123, 123, 123, 123, 123]

This would:

["123".byCodeUnit.permutations].joiner.writeln;
June 27, 2018
On Wednesday, 27 June 2018 at 15:18:05 UTC, Alex wrote:
> On Wednesday, 27 June 2018 at 15:07:57 UTC, Uknown wrote:
>> On Wednesday, 27 June 2018 at 14:50:25 UTC, Alex wrote:
>>> On Wednesday, 27 June 2018 at 14:29:33 UTC, Uknown wrote:
>>>> On Wednesday, 27 June 2018 at 14:21:39 UTC, Alex wrote:
>>>>> On Wednesday, 27 June 2018 at 13:27:46 UTC, Uknown wrote:
>>>>>> [...]
> This would:
>
> ["123".byCodeUnit.permutations].joiner.writeln;

Thanks. This works, but it still seems silly that permutations doesn't just return a range with front returning the original type