On Monday, 24 October 2016 at 15:59:05 UTC, Meta wrote:
On Monday, 24 October 2016 at 15:28:50 UTC, Saurabh Das wrote:
[...]
Yes, that's correct. This is the overload of `repeat` in
question:
https://dlang.org/phobos/std_range.html#.repeat.2
Take!(Repeat!T) repeat(T)(T value, size_t n);
Repeats value exactly n times. Equivalent to
take(repeat(value), n).
Examples:
import std.algorithm : equal;
assert(equal(5.repeat(4), 5.repeat().take(4)));
The variant of repeat that takes a second argument returns a
range with a length; it is not an infinite range, unlike the
first overload of repeat. So for the OP's code:
repeat(8, 10).chunks(3).writeln();
This will throw an AssertError because 10 is not evenly
divisible by 3.
Sure, but:
// This fails:
repeat(8, 9).chunks(3).writeln();
// This works:
repeat(8, 6).chunks(3).writeln();
Both are divisible by 3. Maybe it's a bug?