kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/indexer/testdata/generics/genericfunc.go (about)

     1  package genericfunc
     2  
     3  func main() {
     4  	//- @Map ref Func
     5  	Map([]string{}, func(s string) string { return s })
     6  }
     7  
     8  // - @Map defines/binding Func
     9  // - Func.node/kind function
    10  // - @#0T defines/binding TVar
    11  // - TVar.node/kind tvar
    12  // - @#0U defines/binding UVar
    13  // - UVar.node/kind tvar
    14  // - Func tparam.0 TVar
    15  // - Func tparam.1 UVar
    16  // - @comparable ref Comparable
    17  func Map[T any, U comparable](l []T, f func(T) U) []U {
    18  	//- @U ref UVar
    19  	res := make([]U, len(l))
    20  	for i := 0; i < len(l); i++ {
    21  		//- @T ref TVar
    22  		var t T = l[i]
    23  		res[i] = f(t)
    24  	}
    25  	return res
    26  }
    27  
    28  //- UVar code UCode
    29  //- UCode.kind "BOX"
    30  //- UCode child.0 UVarName
    31  //- UCode child.1 UVarConstraint
    32  //- UVarName child.1 UVarIdent
    33  //- UVarIdent.kind "IDENTIFIER"
    34  //- UVarIdent.pre_text "U"
    35  //- UVarIdent link UVar
    36  //- UVarConstraint.kind "TYPE"
    37  //- UVarConstraint.pre_text "comparable"
    38  //- UVarConstraint link Comparable
    39  
    40  //- Func code FuncCode
    41  //- FuncCode.kind "BOX"
    42  //- FuncCode child.2 FuncParams
    43  //- FuncParams.kind "PARAMETER_LOOKUP_BY_TPARAM"
    44  //- FuncParams.pre_text "["
    45  //- FuncParams.post_text "]"
    46  //- FuncParams.post_child_text ", "
    47  
    48  // kythe/go/indexer/genericfunc_test.Map.T
    49  //- TVar code TVarCode
    50  //- TVarCode.kind "BOX"
    51  //- TVarCode child.0 TVarName
    52  //- TVarName child.0 C
    53  //- TVarName child.1 I
    54  //- C.kind "CONTEXT"
    55  //- C.post_child_text "."
    56  //- C.add_final_list_token "true"
    57  //- C child.0 Pkg
    58  //- C child.1 FuncCtxCode
    59  //- Pkg.kind "IDENTIFIER"
    60  //- Pkg.pre_text "kythe/go/indexer/genericfunc_test"
    61  //- FuncCtxCode.kind "IDENTIFIER"
    62  //- FuncCtxCode.pre_text "Map"
    63  //- I.kind "IDENTIFIER"
    64  //- I.pre_text "T"