On Tuesday, 11 February 2014 at 16:26:06 UTC, Rene Zwanenburg
wrote:
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap
wrote:
Wow! This is GREAT stuff. My use-case is slightly more
complex, and I'm not sure how to best apply this knowledge.
The retro reverses the array which is problematic in itself as
well as losing the starting index location. I have an array
that I'd like to elegantly "rotate". Best way I can show this
is by example of an imaginary rotate function:
auto data = [1,2,3];
assert( data.cycle.rotate(2) == [3,1,2] );
assert( data.cycle.rotate(-2) == [2,3,1] );
Perhaps what I'm doing is too complex requires me making my
own iterator or something. In my quest of writing readable
efficient code, I'm wondering what's the best route here.
Thanks :)
Perhaps something like this?
http://dpaste.dzfl.pl/d4b82b0b5cba
Wait, we can avoid creating that closure and eliminate the map.
This should be a bit faster and not use the GC:
http://dpaste.dzfl.pl/78c65eacfeb1