[swift-evolution] [Proposal] function "return" optional keyword.

Kevin Ballard kevin at sb.org
Sat Dec 19 20:55:14 CST 2015

If Swift ever changes to be Rust-like and have every statement actually be an expression with a non-void type (I believe this was discussed in the thread about replacing ?:), then your proposed behavior is already an implicit part of that change.

But barring a large change like that, I'm against dropping the `return`
here, as it's inconsistent with the rest of the language. The only
construct today that lets you drop the return is a one-line closure, but
that's already something that looks like an expression (`foo.map({ $0.x
})` looks perfectly fine; `foo.map({ return $0.x })` is just unnecessary
syntax). But the last statement of a function isn't an expression, it's
a statement.

-Kevin Ballard

On Sat, Dec 19, 2015, at 05:30 AM, Craig Cruden via swift-evolution wrote:
> When writing short functional code in a function it would be nice if
> the return keyword were an optional keyword.
> Just return the last evaluated expression.
> i.e.
> func flipFunc<T, U>(arg1: T, arg2: U) -> (U, T) {        (arg2,
> arg1)    }
> The keyword return would still be there for breaking out of a
> function.
> _________________________________________________
> swift-evolution mailing list swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151219/ef3ca4a5/attachment.html>

More information about the swift-evolution mailing list