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

Andrew Hoos andrewjhoos at gmail.com
Sat Dec 19 19:22:12 CST 2015

Summary of feedback

Block based API prevents return/break/continue
Can be implemented by an extension without language changes
Vaguely confusable with multiplication

Is easier for new learners
Removes ambiguity of ..< vs ... (again mostly new learners)
shorter than existing syntax

for _ in 0..< 5_000 (current solution)
repeat 5_000 (alternative syntax)
for 5_000

My $.02

If we are going to introduce a new "something" it should either provide a feature that is currently impossible or it should provide a significantly better way to do something that can already be done. With that as my metric I find 5_000.times to be moderately better at best and does not meet my standard for inclusion.

Andrew Hoos

> On Dec 19, 2015, at 16:35, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> I do have an honest question that comes from ignorance rather than malice: has anyone actually used .times in ruby outside of the context of learning or testing?
> I've seen it used to retry a failing operation a certain number of times:
> 	5.times do
> 		return true if do_network_call
> 		sleep 5
> 	end
> 	raise NetworkCallFailedError
> Of course, that requires you to be able to return out of the surrounding function from the `times` loop, which you can do in Ruby but not in Swift.
> -- 
> Brent Royal-Gordon
> Architechies
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list