Comment #0 by bearophile_hugs — 2015-04-24T13:21:14Z
The documentation of std.array.replicate says:
"Returns an array that consists of s (which must be an input range) repeated n times. This function allocates, fills, and returns a new array. For a lazy version, refer to std.range.repeat."
The documentation of std.range.repeat says:
"Repeats value exactly n times. Equivalent to take(repeat(value), n).
assert(equal(5.repeat(4), 5.repeat().take(4)));"
But std.range.repeat is not a lazy replacement for std.array.replicate, as you can see here:
void main() {
import std.stdio, std.range, std.array, std.algorithm;
immutable txt = "abc";
immutable n = 3;
txt.replicate(n).writeln;
txt.repeat(n).writeln;
txt.repeat(n).joiner.writeln;
txt.repeat(n).join.writeln;
}
Output:
abcabcabc
["abc", "abc", "abc"]
abcabcabc
abcabcabc
As you can see you need "repeat(n).joiner" to have the same semantics.
So in the documentation of std.array.replicate I suggest to write something like:
"For a lazy version, refer to std.range.repeat plus std.algorithm.joiner".