[swift-evolution] Proposal: Pattern Matching Partial Function (#111)

Paul Cantrell paul at innig.net
Fri Jan 29 01:10:46 CST 2016


> On Jan 29, 2016, at 1:01 AM, Charles Constant via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I'm still +1 on this.
> 
> I would very much enjoy being able to do this:
> 
> let str = state.map {
> 	case .Cold: 	“Too cold”
> 	case .Hot: 	“Too hot”
> 	default: 	“Just right”
> }


The language currently allows this:

    let str: String
    switch(state) {
        case .Cold: str = "Too cold"
        case .Hot:  str = "Too hot"
        default:    str = "Just right"
    }

While that’s slightly noisier, I’m not convinced the minor additional concision justifies the substantial additional language complexity. I’m not even convinced the new syntax is clearer so much as cleverer.

I’d need to see a much more compelling example to be in favor of this proposal.

Cheers,

Paul


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


More information about the swift-evolution mailing list