1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-11-29 22:38:29 +02:00
Files
fp-go/context/readereither/cancel.go
Dr. Carsten Leue 84c3e3ff88 fix: add support for context sensitive readers
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-07-14 23:52:14 +02:00

18 lines
402 B
Go

package readereither
import (
"context"
E "github.com/ibm/fp-go/either"
)
// withContext wraps an existing ReaderEither and performs a context check for cancellation before deletating
func WithContext[A any](ma ReaderEither[A]) ReaderEither[A] {
return func(ctx context.Context) E.Either[error, A] {
if err := context.Cause(ctx); err != nil {
return E.Left[A](err)
}
return ma(ctx)
}
}