4 ms·
For even more similar look to pattern matching look at Go's type switch. switch i.(type) { case OptionalInterface1: // do some extra thi
by zaphar 12y ago
For even more similar look to pattern matching look at Go's type switch.
switch i.(type) {
case OptionalInterface1:
// do some extra thing we allow
case OptionalInterface2:
// do some other extra thing we allow
}
It's really good when you have a set of mutually exclusive interfaces or types.
- arnehormann 12y agoYou should use switch v := i.(type) so you can access v as the type in a case.
- jerf 12y agoYou can do a passable impression of sum types that way too: http://www.jerf.org/iri/post/2917 http://www.jerf.org/iri/post/2917