MCPcopy
hub / github.com/duke-git/lancet / ExtractPointer

Function ExtractPointer

pointer/pointer.go:66–82  ·  view source on GitHub ↗

ExtractPointer returns the underlying value by the given interface type Play: https://go.dev/play/p/D7HFjeWU2ZP

(value any)

Source from the content-addressed store, hash-verified

64// ExtractPointer returns the underlying value by the given interface type
65// Play: https://go.dev/play/p/D7HFjeWU2ZP
66func ExtractPointer(value any) any {
67 if IsNil(value) {
68 return value
69 }
70 t := reflect.TypeOf(value)
71 v := reflect.ValueOf(value)
72
73 if t.Kind() != reflect.Pointer {
74 return value
75 }
76
77 if v.Elem().IsValid() {
78 return ExtractPointer(v.Elem().Interface())
79 }
80
81 return nil
82}
83
84// IsNil returns true if the given interface is nil or the underlying value is nil.
85func IsNil(i interface{}) bool {

Callers 4

NewFunction · 0.92
mapValueMethod · 0.92
ExampleExtractPointerFunction · 0.85
TestExtractPointerFunction · 0.85

Calls 3

IsNilFunction · 0.85
KindMethod · 0.80
ValueOfMethod · 0.45

Tested by 2

ExampleExtractPointerFunction · 0.68
TestExtractPointerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…