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

Radosław Pietruszewski radexpl at gmail.com
Sat Jan 30 13:11:20 CST 2016


I certainly would prefer if we could use switch (and if/else for that matter) as an expression, instead of some magic syntax usable in `map`. so:

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


— Radek

> On 29 Jan 2016, at 08:10, Paul Cantrell via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Jan 29, 2016, at 1:01 AM, Charles Constant via swift-evolution <swift-evolution at swift.org <mailto: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
> 
> 
> _______________________________________________
> 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/20160130/3f488c57/attachment.html>


More information about the swift-evolution mailing list