If you are ok with using things from std.range you could use something
like this:
```d
import std.range : cycle, drop, take;
import std.stdio : writeln;
int main(string[] args)
{
auto r = [1, 2, 3, 4, 5, 6, 7, 8];
writeln(r.cycle.drop(3).take(r.length));
return 0;
}
```
Kind regar
On Mon, Oct 03, 2022 at 05:38:25PM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
[...]
> Good catch but I think what we want is a copy of the front element, at
> least for InputRanges (.save does not work for File.byLine :/).
One of the things we need to settle in Phobos v2 is what to do with
On Tuesday, 4 October 2022 at 00:38:25 UTC, Ali Çehreli wrote:
Good catch but I think what we want is a copy of the front
element, at least for InputRanges (.save does not work for
File.byLine :/).
What is the generic way of copying an element? I wonder whether
we have to use isSomeString to
On 10/3/22 23:06, Ali Çehreli via Digitalmars-d-learn wrote:
auto rotatedView(R)(R range)
Or even more generic by chaining two slices in case the range permits it:
auto rotatedView(R)(R range, long n = 1)
if (...)
{
if (n == 0) return range;
...
n %= range.length;
On 10/3/22 17:00, Paul Backus wrote:
> On Monday, 3 October 2022 at 21:06:36 UTC, Ali Çehreli wrote:
>> On 10/3/22 13:48, Andrey Zherikov wrote:
>>> a "rotated view".
>>
>> Without indexes:
>>
>> import std.range : empty;
>>
>> auto rotatedView(R)(R range)
>> in (!range.empty)
>> {
>> import s
On Monday, 3 October 2022 at 21:06:36 UTC, Ali Çehreli wrote:
On 10/3/22 13:48, Andrey Zherikov wrote:
a "rotated view".
Without indexes:
import std.range : empty;
auto rotatedView(R)(R range)
in (!range.empty)
{
import std.range : chain, front, only, popFront;
const fr = range.front
On 10/3/22 13:48, Andrey Zherikov wrote:
a "rotated view".
Without indexes:
import std.range : empty;
auto rotatedView(R)(R range)
in (!range.empty)
{
import std.range : chain, front, only, popFront;
const fr = range.front;
range.popFront();
return chain(range, only(fr));
}
v
On Monday, 3 October 2022 at 18:09:05 UTC, Fausto wrote:
Hello all,
I am trying to rotate left an array.
I found a very basic way, and I am not sure if there is
something clever than this :) maybe using slices...
the external for represents how many times you are rotating (in
this case 2
On Monday, 3 October 2022 at 18:09:05 UTC, Fausto wrote:
Hello all,
I am trying to rotate left an array.
I found a very basic way, and I am not sure if there is
something clever than this :) maybe using slices...
Here we can't use slice assignment instead of the inner loop
because
Hello all,
I am trying to rotate left an array.
I found a very basic way, and I am not sure if there is something
clever than this :) maybe using slices...
the external for represents how many times you are rotating (in
this case 2).
```d
void main()
{
import std.range;
import
10 matches
Mail list logo