Hacker News new | ask | show | jobs
by vishvananda 1641 days ago
You could always use a pointer for this, but admittedly it is pretty ugly when compared to a true optional type:

    func f(s *string) string {
        ret := ""
        if s == nil {
            ret = "default"
        } else {
            ret = *s
        }
        return ret
    }

    func main() {
        s := "foo"
        fmt.Println("Hello, " + f(&s))
        fmt.Println("Hello, " + f(nil))
    }