Small but useful Go generic functions.
p := handy.New(42)
fmt.Println(*p) // 42
ss := handy.Slice("foo", "bar")
fmt.Println(ss) // [foo bar]
c := handy.Tern(true, "foo", "bar")
fmt.Println(c) // foo
w := iomock.ErrOnCallWriter(1, iomock.ErrWrite)
err := handy.UnpackError(io.WriteString(w, "foobar"))
fmt.Println(err) // write error
type TestError string
func (s TestError) Error() string {
return string(s)
}
in := fmt.Errorf("wrap: %w", TestError("error"))
fmt.Println(handy.As[TestError](in)) // error true