www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14494] New: Improve std.array.replicate documentation

https://issues.dlang.org/show_bug.cgi?id=14494

          Issue ID: 14494
           Summary: Improve std.array.replicate documentation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: websites
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

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".

--
Apr 24 2015