Skip to content

Instantly share code, notes, and snippets.

@a-voronov
Created May 15, 2018 19:24
Show Gist options
  • Save a-voronov/29b4f2a57e36f59a0944333cdca792c2 to your computer and use it in GitHub Desktop.
Save a-voronov/29b4f2a57e36f59a0944333cdca792c2 to your computer and use it in GitHub Desktop.
What's the name for this data type or approach?
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