[swift-evolution] ternary operator ?: suggestion
Craig Cruden
ccruden at novafore.com
Fri Jan 8 08:30:56 CST 2016
> On 2016-01-08, at 19:58:45, Thorsten Seitz <tseitz42 at icloud.com> wrote:
>
> But then the question arises: shouldn’t { case <pattern>: <expr> … } allow statements, too?
> I would think so.
> In Scala this is allowed, e.g. I can write
> val f: PartialFunction[Any, Int] = { case x: Int => { println(x); x + 1 } }
>
> -Thorsten
Of course…. why would it not…. it just cannot be on the last line (the return value) since println(x) is void. You could have any number of statements, expressions, assignments etc… before finally returning a value.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160108/03a08cc9/attachment.html>
More information about the swift-evolution
mailing list