1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-12-15 23:33:46 +02:00
Files
fp-go/context/readerioeither/generic/cancel.go
Dr. Carsten Leue b25de3c7c3 doc: fix case
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-07-18 15:57:54 +02:00

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