- Learning Functional Programming in Go
- Lex Sheehan
- 61字
- 2021-07-02 23:13:34
The empty interface
Another alternative would be to use the empty interface like so:
type Object interface{}
type Collection []Object
func (list Collection) Contains(e string) bool {
for _, t := range list { if t == e { return true } }
return false
}
However, reflection or typecasting would be required and that would again adversely affect the performance.