November 2017
Intermediate to advanced
670 pages
17h 35m
English
The Equals method of Int will check whether other types are equal, using whatever logic we deem appropriate:
type Int intfunc (i Int) Equals(e Equals) bool { intVal := int(i) switch x := e.(type) { case Int: return intVal == int(x) case String: convertedInt, err := strconv.Atoi(string(x)) if err != nil { return false } return intVal == convertedInt default: return false }}