Example #1
0
File: chan.go Project: ttthzy/qlang
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)}
}
Example #2
0
// 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()
}
Example #3
0
// SliceOf makes a slice type.
//
func SliceOf(typ interface{}) interface{} {

	return reflect.SliceOf(types.Reflect(typ))
}
Example #4
0
// MapOf makes a map type.
//
func MapOf(key, val interface{}) interface{} {

	return reflect.MapOf(types.Reflect(key), types.Reflect(val))
}
Example #5
0
// Mkmap makes a new map object.
//
func Mkmap(typ interface{}, n ...int) interface{} {

	return reflect.MakeMap(types.Reflect(typ)).Interface()
}
Example #6
0
File: chan.go Project: ttthzy/qlang
func ChanOf(typ interface{}) interface{} {

	return reflect.ChanOf(reflect.BothDir, types.Reflect(typ))
}