[swift-evolution] Allowing non-binding pattern matching as a Bool expression?

Alex Lew alexl.mail+swift at gmail.com
Mon Dec 7 22:05:51 CST 2015

Hi all,

Curious to hear thoughts on allowing non-binding pattern matches to be used
as boolean values outside of an if, guard, for...in, while, switch, etc.
Something like:

enum List<T> {
     case Empty
     indirect case Link(T, List<T>)

     func isEmpty() -> Bool {
          return case .Empty = self

It gets rid of some boilerplate (explicit return true and return false),
and seems intuitive that it would work given that you can already do

if case .Empty = self {
     return true
} else {
     return false

I haven't really thought through all the implications here, so there's
probably something I'm missing. It also may be useful only in such limited
situations that it's not worth the trouble to add.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151207/87481738/attachment.html>

More information about the swift-evolution mailing list