Hi
I tried to write a function to produce an array of count indentical elements:
func replicateWithReduce<T>(elem: T, count: Int) -> [T]
{
return (0 ..< count).reduce([T]()) { return $0.append(elem) }
}
Normally with reduce, the 1st param sets the type of the return, here obviously [T], and the successive $1 values come from the type of the element of the sequence, which here is not used. So this looks right to me, for the purpose.
But it gives me an error pointing to the [T](): "Cannot convert value of type '[T]' to expected argument type '[_]'
I don't know why that error is occurring. Can anyone explain this?
TIA
Mark