Print ranges from an array

Say I have a relatively large array of values

~o = (1..1000) 

i want to read sections/ranges of it, that’s ok:

z = ~o.copyRange(0, 4);

however i’m struggling to find a way to recursively increment the range values, so that next i can read another group of 5 values, as in:

z = ~o.copyRange(0, 4);
z = ~o.copyRange(5, 9);
z = ~o.copyRange(10, 14);

but with a more efficient, automated way :slight_smile:

i guess i’ll have to put whatever it ends up being inside a Pfunc so that i can run it as a Pattern, but i’m stuck figuring out what the trick is

~o = (1..1000);

~p = ~o.clump(5);
-> [ [ 1, 2, 3, 4, 5 ], [ 6, 7, 8, 9, 10 ], ... ]

~p.do(_.postln);

Not necessarily.

Pseries(0, 1, inf).clump(5).asStream.nextN(3)
-> [ [ 0, 1, 2, 3, 4 ], [ 5, 6, 7, 8, 9 ], [ 10, 11, 12, 13, 14 ] ]

hjh

2 Likes

Amazing, James. Many thanks.
I totally missed .clump!!!