mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-29 22:38:29 +02:00
18 lines
402 B
Go
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)
|
|
}
|
|
}
|