Created
November 14, 2015 08:29
-
-
Save motokiee/a0abbadb73d3019d77b8 to your computer and use it in GitHub Desktop.
Associated Typeでパターンマッチ #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Option { | |
case Regular(MoreOption) | |
case Irregular(MoreOption) | |
} | |
enum MoreOption { | |
case One, Two, Three | |
} | |
let os1 = Option.Regular(.One) | |
let os2 = Option.Regular(.Two) | |
let os3 = Option.Regular(.Three) | |
let oi1 = Option.Irregular(.One) | |
let oi2 = Option.Irregular(.Two) | |
let oi3 = Option.Irregular(.Three) | |
switch os1 { | |
case Option.Regular(.One): print("Option.Regular.One") | |
case Option.Regular(_): print("Option.Regular ") | |
case Option.Irregular(_): print("Option.Irregular") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment