mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-25 00:36:54 +02:00
20 lines
554 B
Go
20 lines
554 B
Go
![]() |
package generic
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
CIOE "github.com/ibm/fp-go/context/ioeither/generic"
|
||
|
E "github.com/ibm/fp-go/either"
|
||
|
IOE "github.com/ibm/fp-go/ioeither/generic"
|
||
|
)
|
||
|
|
||
|
// withContext wraps an existing ReaderIOEither and performs a context check for cancellation before delegating
|
||
|
func WithContext[GRA ~func(context.Context) GIOA, GIOA ~func() E.Either[error, A], A any](ma GRA) GRA {
|
||
|
return func(ctx context.Context) GIOA {
|
||
|
if err := context.Cause(ctx); err != nil {
|
||
|
return IOE.Left[GIOA](err)
|
||
|
}
|
||
|
return CIOE.WithContext(ctx, ma(ctx))
|
||
|
}
|
||
|
}
|