reflectish

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package reflectish provides common reflection utilities that extend Go's standard "reflect" library.

It offers:

  • IndirectDeep: recursively dereferences pointers until a non-pointer value is reached.
  • Interface: the panic-safe form of reflect.Value.Interface (nil for the invalid Value).
  • IndirectInterface: deeply dereferences pointers and returns the value as any (nil through nil pointers).
  • LengthOf: returns the length of supported types (arrays, slices, maps, strings, channels), along with a boolean indicating support.

Usage:

import "github.com/amberpixels/k1/reflectish"

// Deeply dereference pointers
val := reflect.ValueOf(&&myStruct)
root := reflectish.IndirectDeep(val)

// Get length of a slice, map, etc.
length, ok := reflectish.LengthOf([]int{1,2,3})
if ok {
    fmt.Println("Length:", length)
}

Package reflectish is intended as a lightweight helper for reflection-based operations.

Package reflectish contains helpers that extends standard reflect library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndirectDeep

func IndirectDeep(v reflect.Value) reflect.Value

IndirectDeep does reflect.Indirect deeply.

func IndirectInterface added in v0.1.6

func IndirectInterface(v reflect.Value) any

IndirectInterface deeply dereferences pointers and returns the underlying value as any, yielding nil when it dereferences through a nil pointer. It is shorthand for Interface(IndirectDeep(v)).

func Interface added in v0.1.5

func Interface(v reflect.Value) any

Interface is the panic-safe equivalent of reflect.Value.Interface.

reflect.Value.Interface panics on the zero (invalid) Value — which is exactly what IndirectDeep yields when it dereferences through a nil pointer. Interface returns nil for an invalid Value instead, so the two compose cleanly:

v := reflectish.Interface(reflectish.IndirectDeep(rv)) // nil for nil pointers

func LengthOf

func LengthOf(a any) (int, bool)

LengthOf returns length of a given type.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL