This commit is contained in:
Joshua Bell 2026-01-26 21:41:26 -06:00
parent 07ec5529ac
commit f501abe660
532 changed files with 271781 additions and 0 deletions

22
vendor/github.com/samber/mo/do.go generated vendored Normal file
View file

@ -0,0 +1,22 @@
package mo
import (
"errors"
"fmt"
)
// Do executes a function within a monadic context, capturing any errors that occur.
// If the function executes successfully, its result is wrapped in a successful Result.
// If the function panics (indicating a failure), the panic is caught and converted into an error Result.
func Do[T any](fn func() T) (result Result[T]) {
defer func() {
if r := recover(); r != nil {
if err, ok := r.(error); ok {
result = Err[T](err)
} else {
result = Err[T](errors.New(fmt.Sprint(r)))
}
}
}()
return Ok(fn())
}