Swift string multiplication I like Ruby's string multiplication so I thought I'd see if I could do it in Swift. I came up with these implementations: 

@infix func * (left: String, right: Int) -&gt; String {
    var result = ""
    for _ in 0..right {
        result += left
    }
    return result
}

operator infix ** {}

@infix func ** (left: String, right: Int) -&gt; String {
    return Array(count: right, repeatedValue: left).reduce("", +)
}

println("Andrew rules! " * 42)
println("Andrew rules! " ** 42)


Anyone have improvements or other implementations?
As Flambino points out, the method is very problematic for negative integers.  

You need to either change the function to only accept unsigned integers or come up with some solution that makes sense for negative numbers.

In general though, I don't particularly like operator-overloading.  Using functions/methods means there's some plain-English name to the operation you're performing that will give me some sort of hint at what the operation does so I don't have to guess.

As someone coming from an Objective-C/Foundation background (which will likely be most Swift programmers) and having zero Ruby experience, I could maybe guess at what the first one does:

println("Andrew rules! " * 42)


But as for the second one?

println("Andrew rules! " ** 42)


I'd have absolutely no clue.  And I doubt I'd be the only one.

The amount of time you save typing ** instead of a more descriptive function name (which the IDE will autocomplete for you meaning the amount of time is basically the same either way) is definitely not worth the amount of time that other programmers behind you take to go figure out what this does:

let myVar = "Hello world!" ** 27


There's not even the slightest hint as to what this returns, and there's no descriptive function name to give any clues... so now I have to go hunt down where ever you've put the operator overload function for a string/int.