3 ms·
I remember the first time I tried to use them. I just wanted to make some small functions for logging different types of things. I wanted to use parametric pol
by mijoharas 7y ago
I remember the first time I tried to use them.
I just wanted to make some small functions for logging different types of things. I wanted to use parametric polymorphism to dispatch to different functions depending on the type of the thing I passed in. I think I ended up creating a few `log_type_foo` and `log_type_bar` functions rather than the single `log` function I wanted. It looked really ugly to my eye.
The thing I really wanted was parametric polymorphism. I seem to remember reading something where the go people think this is equivalent to generics.
EDIT: clarity
- majewsky 7y agoGo supports parametric polymorphism by specifying arguments with an interface type. func DoWorkWith(foo Loggable) { ... } type Loggable interface { //for example LogTo(os.Writer) }