1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-06-17 00:07:49 +02:00
Files
fp-go/errors/conv.go

17 lines
298 B
Go
Raw Normal View History

package errors
import (
"errors"
O "github.com/IBM/fp-go/option"
)
// As tries to extract the error of desired type from the given error
func As[A error]() func(error) O.Option[A] {
return O.FromValidation(func(err error) (A, bool) {
var a A
ok := errors.As(err, &a)
return a, ok
})
}