Skip to content

Commit

Permalink
feat: Zero
Browse files Browse the repository at this point in the history
fix: MethodOf
  • Loading branch information
Drelf2018 committed Jan 23, 2024
1 parent 6175d32 commit 14e5c09
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func Type(typ reflect.Type) uintptr {
return Ptr(reflect.Zero(typ).Interface())
}

// Zero returns a Value representing the zero value for the specified type.
// The result is addressable and settable.
func Zero(typ reflect.Type) reflect.Value {
return reflect.New(typ).Elem()
}

func Fields(elem reflect.Type) Chan.Chan[reflect.StructField] {
if elem.Kind() == reflect.Ptr {
elem = elem.Elem()
Expand Down Expand Up @@ -77,8 +83,7 @@ func FieldOf(elem reflect.Type) []reflect.StructField {
}

func MethodOf(value reflect.Value) map[reflect.Method]reflect.Value {
if value.Kind() != reflect.Struct && (value.Kind() != reflect.Ptr || value.Elem().Kind() != reflect.Struct) {
// panic(ErrValue{value})
if value.Kind() == reflect.Interface && value.IsNil() {
return nil
}
elem := value.Type()
Expand All @@ -90,8 +95,7 @@ func MethodOf(value reflect.Value) map[reflect.Method]reflect.Value {
}

func MethodFuncOf(value reflect.Value) map[string]any {
if value.Kind() != reflect.Struct && (value.Kind() != reflect.Ptr || value.Elem().Kind() != reflect.Struct) {
// panic(ErrValue{value})
if value.Kind() == reflect.Interface && value.IsNil() {
return nil
}
elem := value.Type()
Expand Down

0 comments on commit 14e5c09

Please sign in to comment.