x/pkg.go
Colin Henry fe49018479
Some checks failed
Go / build (1.19) (push) Failing after 22s
added new check capability and added assets to a few other packages
2024-09-28 15:19:00 -07:00

40 lines
585 B
Go

package x
import (
"errors"
)
func Assert(cond bool, msg string) {
if cond {
panic(errors.New(msg))
}
}
func Check(cond bool, err error) *invariants {
return new(invariants).Check(cond, err)
}
type invariants struct {
errs []error
}
func (i *invariants) Check(cond bool, err error) *invariants {
if !cond {
i.errs = append(i.errs, err)
}
return i
}
func (i *invariants) Join() error {
return errors.Join(i.errs...)
}
func (i *invariants) First() error {
if len(i.errs) > 0 {
return i.errs[0]
}
return nil
}
func (i *invariants) All() []error {
return i.errs
}