import std.stdio: writeln; import std.range: chunks; void main() { chunks("abcd"d, 0).writeln; } Prints an unbound range of empty strings, I think this is not good: ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ... I suggest to refuse the chunkSize = 0 with a pre-condition (or worse with an enforce). An alternative solution is to make 0 a special case, and return the whole iterable: std.range.chunks("abcd"d, 0).writeln; ==> ["abcd"]
Hmm, not sure what the benefit of rejecting chunks(r, 0) is. Sure, it's pointless to take a range in chunks of 0, but it's well-defined. My worry is that someone is using chunks in some generic code somewhere that genuinely asks for chunkSize of 0 in some cases. Implementing your suggestion will break their code for no benefit.
> I suggest to refuse the chunkSize = 0 with a pre-condition (or worse with an > enforce). You have an assertion for this in Chunk ctor, so you can detect the problem when testing.
(In reply to bb.temp from comment #2) > You have an assertion for this in Chunk ctor, so you can detect the problem > when testing. The assert needs to be documented, though: https://github.com/D-Programming-Language/phobos/pull/3858