2023-07-14 23:52:14 +02:00
|
|
|
package readerioeither
|
|
|
|
|
|
|
|
import (
|
2023-07-18 15:57:54 +02:00
|
|
|
G "github.com/IBM/fp-go/context/readerioeither/generic"
|
2023-07-14 23:52:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource
|
2023-07-18 15:24:00 +02:00
|
|
|
func WithResource[R, A, ANY any](onCreate ReaderIOEither[R], onRelease func(R) ReaderIOEither[ANY]) func(func(R) ReaderIOEither[A]) ReaderIOEither[A] {
|
2023-07-14 23:52:14 +02:00
|
|
|
// wraps the callback functions with a context check
|
2023-07-18 15:24:00 +02:00
|
|
|
return G.WithResource[ReaderIOEither[A]](onCreate, onRelease)
|
2023-07-14 23:52:14 +02:00
|
|
|
}
|