Skip to content

mateothegreat/util

Repository files navigation

util

Features

Feature Description
values A package for working with values.
values.IsZero A function that checks if a value is zero.
values.Pick A function that picks a value from a map.
values.PickHasValue A function that picks a value from a list of values.
values.PickHasValue A function that picks a value from a list of values.

Values

IsZero

IsZero checks if a value is zero and accepts all types.

Performance Comparison
  • Type Switch (Current - for handled types):
    • ~0.5-2 nanoseconds - Compiles to efficient jump tables
    • Extremely fast, direct comparisons
    • No heap allocations
  • Reflection Approach:
    • ~5-15 nanoseconds - Modern Go has optimized reflect.Value.IsZero()
    • Still very fast for most use cases
    • Correct for ALL types automatically
  • Real-World Impact:
    • 3-10x slower with reflection, but we're talking nanoseconds
    • Unless you're calling IsZero millions of times in tight loops, the difference is negligible
    • Correctness trumps micro-optimization

Why Hybrid is Better:

  • 90%+ of use cases hit the fast type-switch path
  • 100% correctness for edge cases via reflection fallback
  • Maintainable - no need to manually handle every possible type
  • Performance where it matters - common types stay fast

Pick

Pick picks a value from a map.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages