Am 17.01.2011 19:10, schrieb Andrei Alexandrescu:
std.range has a function repeat that repeats one value forever. For example,
repeat(42) is an infinite range containing 42, 42, 42,...

The same module also has a function replicate that repeats one value a specific
number of times. In fact, replicate can be expressed as an overload of repeat,
so that's what I just did (not committed yet): repeat(42, 100) repeats 42 one
hundred times, repeat(42) repeats 42 forever. I'll put replicate on the
deprecation chute.

So far so good. Now, string has its own repeat. repeat("abc", 2) returns the
string "abcabc".

I want to generalize the functionality in string's repeat and move it outside
std.string. There is an obvious semantic clash here. If you say repeat("abc", 3)
did you mean one string "abcabcabc" or three strings "abc", "abc", and "abc"?

So we need distinct names for the functions. One repeats one value, the other
repeats a range. Moreover, I'm thinking sometimes you want to repeat a range
lazily, i.e. instead of producing "abcabc" just return a range that looks like 
it.

Ideas for a good naming scheme are welcome.


Andrei

You could only supply repeat, returning ["abc","abc",..]
And also concat (is there really no concat in std.algorithm? Maybe bringToFront.. but a concat that gets a range of ranges may be useful) so people can do something like
 concat(repeat("abc", 42))
(functional style)

Cheers,
- Daniel

Reply via email to