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

Thorsten Seitz tseitz42 at icloud.com
Mon Feb 8 09:54:14 CST 2016



> Am 07.02.2016 um 16:47 schrieb Dany St-Amant via swift-evolution <swift-evolution at swift.org>:
> 
> Assuming this implicit return part of this proposal get generalized, could we instead of the dedicated match function have a generic way to feed the parameters to the closure at the start, where it would make sense for the desired switch usage.
> 
> let str:String = (state) -> { switch $0 { case .Cold: "Too Cold"; case .Hot: "Too Hot"; default: "Just right" } }

That's easy, just use the match() function from the proposal:

let str:String = match(state) { switch $0 { case .Cold: "Too Cold"; case .Hot: "Too Hot"; default: "Just right" } }

No new syntax needed for that.

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


More information about the swift-evolution mailing list