Skip to content

Commit 4044b2c

Browse files
committed
reflect: Add SliceOf, ArrayOf, StructOf, MapOf, FuncOf
1 parent fdf075a commit 4044b2c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/reflect/type.go

+30
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,33 @@ type StructTag = reflectlite.StructTag
499499
func TypeFor[T any]() Type {
500500
return toType(reflectlite.TypeFor[T]())
501501
}
502+
503+
func SliceOf(t Type) Type {
504+
return toType(reflectlite.SliceOf(toRawType(t)))
505+
}
506+
507+
func ArrayOf(n int, t Type) Type {
508+
return toType(reflectlite.ArrayOf(n, toRawType(t)))
509+
}
510+
511+
func StructOf([]StructField) Type {
512+
return toType(reflectlite.StructOf([]reflectlite.StructField{}))
513+
}
514+
515+
func MapOf(key, value Type) Type {
516+
return toType(reflectlite.MapOf(toRawType(key), toRawType(value)))
517+
}
518+
519+
func FuncOf(in, out []Type, variadic bool) Type {
520+
rawIn := make([]*reflectlite.RawType, len(in))
521+
for i, t := range in {
522+
rawIn[i] = toRawType(t)
523+
}
524+
525+
rawOut := make([]*reflectlite.RawType, len(out))
526+
for i, t := range out {
527+
rawOut[i] = toRawType(t)
528+
}
529+
530+
return toType(reflectlite.FuncOf(rawIn, rawOut, variadic))
531+
}

0 commit comments

Comments
 (0)