what am i even doing

master
Jordan Orelli 3 years ago
parent b79fb00f2e
commit 301da04f9b

@ -27,7 +27,7 @@ func strip[X any](f func(X) error) func(interface{}) error {
return func(v interface{}) error { return func(v interface{}) error {
vv, ok := v.(X) vv, ok := v.(X)
if !ok { if !ok {
return fmt.Errorf("unable to merge value of type %T into value of type %T: %w", v, vv, typeMismatch) return fmt.Errorf("unexpected %T value, expected %T instead: %w", v, vv, typeMismatch)
} }
return f(vv) return f(vv)
} }

@ -0,0 +1,22 @@
package ref
import (
"fmt"
)
// New creates a reference for a given pointer
func New[T any](v *T) Ref[T] {
if v == nil {
var zero T
return Ref[T]{ptr: &zero}
}
return Ref[T]{ptr: v}
}
// Ref is a read reference to some value T
type Ref[T any] struct { ptr *T }
// Val reads the value for this reference
func (r Ref[T]) Val() T { return *r.ptr }
func (r Ref[T]) String() string { return fmt.Sprintf("ref{%s}", *r.ptr) }
Loading…
Cancel
Save