1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-06-19 00:17:48 +02:00
Files
fp-go/errors/conv.go
Dr. Carsten Leue c07df5c771 initial checkin
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-07-07 22:31:06 +02:00

17 lines
298 B
Go

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
})
}