package main

import (
        "fmt"
        "reflect"
)
import "golang.org/x/exp/constraints"
// Double returns a new slice that contains all the elements of s, doubled.
func Double[E constraints.Integer](s []E) []E {
        r := make([]E, len(s))
        for i, v := range s {
                r[i] = v
        }
        return r
}

func main() {
        // MySlice is a slice of ints.
        type MySlice []int

        // The type of V1 will be []int, not MySlice.
        // Here we are using function argument type inference,
        // but not constraint type inference.
        var V1 = Double(MySlice{1})
        fmt.Println(reflect.TypeOf(V1).String())
}

why use function argument type infer, and why function argument type infer 
int to []int?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f102326a-5cf6-40dc-bd57-268016284aecn%40googlegroups.com.

Reply via email to