repeat

so so at so.do
Tue Jan 18 09:15:50 PST 2011


On Mon, 17 Jan 2011 20:53:33 +0200, Adam Ruppe <destructionator at gmail.com>  
wrote:

> It seems to me that you actually want two separate functions:
>
> repeat("abc", 3) => ["abc", "abc", "abc"]
>
> join(repeat("abc", 3)) => "abcabcabc"
>
>
> A join function already exists in std.string and does this, although
> it expects a second argument for word separator. I'd be ok with adding
> a default arg to it, the empty string, so this works.
>
>
> Indeed, we could do lazy this same way... have both return the
> lazy ranges, and if your want the array, just call array() on it.
> Though I could see that being annoying with strings - the array
> probably is the common case, but this would be more conceptually pure.

As always, Adam has the solution!
Or maybe overload it like:

join("abc", 3)


More information about the Digitalmars-d mailing list