docs/data/core-assert.md
Does nothing when condition is true; otherwise panics.
// Base variant with optional message
age := 12
lo.Assert(age >= 15, "user age must be >= 15")
// panics: "user age must be >= 15"
// Without message - panics with default message
x := -1
lo.Assert(x > 0)
// panics: "assertion failed: condition is not true"
// Formatted variant with custom message
age = 12
lo.Assertf(age >= 15, "user age must be >= 15, got %d", age)
// panics: "user age must be >= 15, got 12"
// When condition is true - no panic
age = 20
lo.Assert(age >= 15, "user age must be >= 15")
// continues normally
Replace lo.Assert and lo.Assertf with your own statement:
lo.Assertf = func(condition bool, format string, args ...any) {
if !condition {
panic(fmt.Errorf("%s: %s", "customErr", fmt.Sprintf(format, args...)))
}
}