# Allowing non-binding pattern matching as a Bool expression?

**URL:** <https://forums.swift.org/t/allowing-non-binding-pattern-matching-as-a-bool-expression/294>\
**Category:** Discussion\
**Created:** [December 8, 2015, 4:05am UTC](https://forums.swift.org/t/allowing-non-binding-pattern-matching-as-a-bool-expression/294 "2015-12-08T04:05:51Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Andrew](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/andrew/32/949_2.png) [@Andrew](https://forums.swift.org/u/Andrew)\
**Post date:** [December 8, 2015, 10:31am UTC](https://forums.swift.org/t/allowing-non-binding-pattern-matching-as-a-bool-expression/294/2 "2015-12-08T10:31:33Z")

</div>

I've wanted similar too. Although it may be better, instead of Bool, to  
have it as an optional tuple, the reason I suggest this is so that you can  
get the associated type. For example:

case let .Link(value,link) = self

So your example could be written:

func isEmpty() -\> Bool {  
&nbsp;&nbsp;&nbsp;&nbsp;return (case .Empty = self) != nil  
}

However I'm not sure about this syntax, perhaps something like this:

func isEmpty() -\> Bool {  
&nbsp;&nbsp;&nbsp;&nbsp;return self is case .Empty  
}

Alternatively if you want the value you could do:

let (value, link) = self as? case .Link

> **···**
>
> On Tue, Dec 8, 2015 at 3:05 PM, Alex Lew via swift-evolution \< swift-evolution@swift.org\> wrote:
> 
> > 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\> {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case Empty  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;indirect case Link(T, List\<T\>)
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func isEmpty() -\> Bool {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return case .Empty = self  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > 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 {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true  
> > } else {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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.
> > 
> > -Alex
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

_[View the full topic](https://forums.swift.org/t/allowing-non-binding-pattern-matching-as-a-bool-expression/294)._
