[swift-evolution] Proposal: Add .times method to Integer type

Radosław Pietruszewski radexpl at gmail.com
Fri Dec 18 14:32:54 CST 2015


> 
> My personal opinion on this is that 5.times { stuff} offers no benefits over “repeat 5 { stuff }”, so I’d rather see the later (if anything).
> 
> This is all shades of gray with no clear answer.  We generally want to have standard APIs pay for themselves and avoid confusion.  I agree with DaveA’s points upthread.  If you contrast it with forEach, forEach (barely!) pays for itself by allowing things like:
> 
> 	collection.forEach(curriedMethod)
> 
> That benefit doesn’t translate to “.times".
> 
> -Chris

Thanks for weighing in!

The benefit of `5.times` vs `repeat 5` is that the former is (and can easily be) defined in Swift, not as a language-level feature. OTOH `repeat 5` is a bit more useful because it allows returning/breaking/etc.

But I also understand the argument that this feature isn’t worth it at all. (There’s already a lot of libraries extending stdlib with things of this sort!)

— Radek


More information about the swift-evolution mailing list