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

Maximilian Hünenberger m.huenenberger at me.com
Thu Feb 4 10:15:22 CST 2016


-0.5 against keeping "cases".
I see it as a replacement for dictionary literal "pattern matching":

[1 : "one", 2 : "two", 3 : "three"][1] ?? "undefined"

vs

match(1) {
    cases 1 : "one", 2 : "two", 3 : "three"
    default: "undefined"
}

"cases" adds exhaustiveness and is relatively concise.

Even though it would be nice to have but I don’t think that I would use it frequently.
In addition, to be more consistent with "case", "cases" would introduce pattern matching which doesn’t seem right with this concise syntax.

> Can we have a vote on removing / keeping the cases clause.  I personally would not typically use it, but there was a split on whether to keep it or delete it so I just kept it in the original until — as I expected — it would be dropped during review (assuming it has a chance of passing).
> 
> I though, do not find cases to be particularly hard to read if you have 10 key/value pairs over two lines…. and no mixture….. readability is of the sample in the document is concise in that example and quite readable for me (but I would probably still not use it).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160204/46e4963a/attachment.html>


More information about the swift-evolution mailing list