range chunks

Adrian Matoga epi at atari8.info
Thu Aug 5 19:42:49 PDT 2010


Hi,

Is there any off the shelf solution for iterating over a range by 
chunks? Example:

int[] arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
int i;
foreach (chunk; chunks(arr, 3))
{
	assert(chunk == arr[i * 3 .. min(i * 3 + 3, arr.length)]);
}

(should substitute [1, 2, 3], [4, 5, 6], [7, 8, 9], [10] for chunk in 
subsequent iterations)

Regards,
Adrian Matoga


More information about the Digitalmars-d mailing list