[swift-evolution] [Idea] return if / return unless

Julian Dunskus julian.dunskus at gmail.com
Thu Aug 4 08:38:35 CDT 2016

How often have you written something like the following?

if indexPath.row == 0 { return }

guard let thing = things[index] else { return nil }

I propose adding some syntactic sugar to make such statements more readable and simple to write:

return if indexPath.row == 0

return nil unless let thing = things[index]

I don’t know how easy or hard this would be to implement, but I think it would improve some code significantly.

–Julian Dunskus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160804/a5b696f3/attachment.html>

More information about the swift-evolution mailing list