I'm trying to write a generic List
container in Go so I can better learn how type parameters work.
Currently I'm working on a Map
method that takes in a mapper function and returns a new list that has every element mapped.
Here is a part of the code:
type List[T any] []*T
func (list List[T]) Map[E](mapper func(int, *T) *E) List[E] {
// Implementation details
}
This code will error out with "method must have no type parameters". Is there a way to properly do it without using List[interface{}]
as the out type?