func Mkchan(typ interface{}, buffer ...int) *qlang.Chan { n := 0 if len(buffer) > 0 { n = buffer[0] } t := reflect.ChanOf(reflect.BothDir, types.Reflect(typ)) return &qlang.Chan{Data: reflect.MakeChan(t, n)} }
// Mkslice returns a new slice. // func Mkslice(typ interface{}, args ...interface{}) interface{} { n, cap := 0, 0 if len(args) == 1 { if v, ok := args[0].(int); ok { n, cap = v, v } else { panic("second param type of func `slice` must be `int`") } } else if len(args) > 1 { if v, ok := args[0].(int); ok { n = v } else { panic("2nd param type of func `slice` must be `int`") } if v, ok := args[1].(int); ok { cap = v } else { panic("3rd param type of func `slice` must be `int`") } } typSlice := reflect.SliceOf(types.Reflect(typ)) return reflect.MakeSlice(typSlice, n, cap).Interface() }
// SliceOf makes a slice type. // func SliceOf(typ interface{}) interface{} { return reflect.SliceOf(types.Reflect(typ)) }
// MapOf makes a map type. // func MapOf(key, val interface{}) interface{} { return reflect.MapOf(types.Reflect(key), types.Reflect(val)) }
// Mkmap makes a new map object. // func Mkmap(typ interface{}, n ...int) interface{} { return reflect.MakeMap(types.Reflect(typ)).Interface() }
func ChanOf(typ interface{}) interface{} { return reflect.ChanOf(reflect.BothDir, types.Reflect(typ)) }