must

package
v2.0.15 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package must implements

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchFunc

func CatchFunc[X any](f func() X) func() (x X, err error)

CatchFunc takes a function f() => x that may panic, and instead returns a function f() => (x, error).

func Check

func Check(err error) error

Check panics if the error is not nil. Otherwise, it returns a nil error (so that it is convenient to chain).

func Func

func Func[X any](
	f func() (X, error),
) func() X

Func takes a function f() => (x, error), and returns a function f() => x that may panic in the event of error.

func Never added in v2.0.13

func Never(args ...interface{})

Never signifies code that should never be reached. It raises a panic when called.

The args parameter defines an optional fmt.Sprintf-style format string and arguments.

func Ok

func Ok[T any](t T, ok bool) T

Ok accepts a (value, ok) tuple as input and panics if ok is false, otherwise returns value.

func Result

func Result[T any](t T, err error) T

Result accepts a (value, err) tuple as input and panics if err != nil, otherwise returns value. The error raised by panic is wrapped in another error.

For example, must.Result(os.Open("doesnotexist")) may panic with an error like "unexpected error in must.Result[*os.File]: open doesnotexist: no such file or directory". On success, returns *os.File

func True added in v2.0.15

func True(q bool)

True panics if the provided boolean is false.

Types

This section is empty.

Jump to

Keyboard shortcuts

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