Hacker News new | ask | show | jobs
by zaphar 4210 days 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.
2 comments

You can do a passable impression of sum types that way too: http://www.jerf.org/iri/post/2917
You should use switch v := i.(type) so you can access v as the type in a case.