On Thu, Aug 17, 2017 at 8:25 PM, Erica Sadun <er...@ericasadun.com> wrote:

> `repeatElement((), count: 5)` is better than `1 ... 5`, but
> `Count(3).map({ UIView() })` is far more elegant.  I'd still probably go
> with an array initializer or `5.elements(of: UIView())`. I don't think I'm
> overstating how common this pattern is, and `Array(repeating:count:)` feels
> _close_ but not close enough.
>

The first two have the benefit of being currently existing APIs; they
capture the semantics perfectly, as I've argued, and I simply don't see how
they are impaired in elegance in any way--certainly not enough to justify a
standard library addition to create a third way of spelling the same thing.
Ultimately, any user is free to define something like:

```
func * <T>(lhs: Int, rhs: @autoclosure () throws -> T) rethrows -> [T] {
  return try repeatElement((), count: lhs).map { try rhs() }
}

5 * UIView()
```
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to