mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
25 lines
317 B
Go
25 lines
317 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func SomeFunc[T int | string](defaultValue T) T {
|
|
switch v := any(&defaultValue).(type) {
|
|
case *string:
|
|
*v = *v + " abc"
|
|
case *int:
|
|
*v -= 234
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println(SomeFunc("test"))
|
|
fmt.Println(SomeFunc(1234))
|
|
}
|
|
|
|
// Output:
|
|
// test abc
|
|
// 1000
|