Created
May 15, 2018 19:24
-
-
Save a-voronov/29b4f2a57e36f59a0944333cdca792c2 to your computer and use it in GitHub Desktop.
What's the name for this data type or approach?
This file contains 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 S { | |
case a, b | |
} | |
struct MapOfS<T> { | |
private var a: T, b: T | |
subscript(_ s: S) -> T { | |
get { | |
switch s { | |
case .a: return a | |
case .b: return b | |
} | |
} | |
set { | |
switch s { | |
case .a: a = newValue | |
case .b: b = newValue | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment