Bug 14494 – Improve std.array.replicate documentation

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-24T13:21:00Z
Last change time
2016-12-23T21:08:30Z
Keywords
trivial
Assigned to
nobody
Creator
bearophile_hugs

Comments

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".
Comment #1 by andrei — 2016-12-23T21:07:33Z
Comment #2 by andrei — 2016-12-23T21:08:30Z
(Doc refers to std.range.repeat, not joiner)