On Mon, Feb 22, 2021 at 3:04 PM Khosrow Afroozeh
wrote:
> 2. It seems impossible to implement a type-safe Map function. The
> following code:
>
> func (l List[T]) Map(f func[U any](v T) U) List[U] {
> return nil
> }
>
> will not compile, with the error: function type cannot have type
> parame
Make Map a function not a method (not sure it can be made a method they way
you’re trying):
package main
import (
"fmt"
"strconv"
)
type List[T any] []T
func ToList[T any](v []T) List[T] {
return List[T](v)
}
func Map[T, U any](l List[T], f func(v T) U) List[U] {
I was playing with the go2go playground, and while implementing a toy List
type, came across a few issues (Sorry if these have been discussed before,
my cursory search didn't turn out to find anything). Given the type
type List[T any] []T
1. The current go2go implementation does not allow one t