1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-11-25 22:21:49 +02:00

fix: add support for context sensitive readers

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-14 23:52:14 +02:00
parent 5020437b6a
commit 84c3e3ff88
101 changed files with 4440 additions and 13 deletions

View File

@@ -0,0 +1,33 @@
package generic
import (
ET "github.com/ibm/fp-go/either"
IOE "github.com/ibm/fp-go/ioeither/generic"
)
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource
func WithResource[
GEA ~func(L) TEA,
GER ~func(L) TER,
GEANY ~func(L) TEANY,
TEA ~func() ET.Either[E, A],
TER ~func() ET.Either[E, R],
TEANY ~func() ET.Either[E, ANY],
L, E, R, A, ANY any](onCreate GER, onRelease func(R) GEANY) func(func(R) GEA) GEA {
return func(f func(R) GEA) GEA {
return func(l L) TEA {
// dispatch to the generic implementation
return IOE.WithResource[TEA](
onCreate(l),
func(r R) TEANY {
return onRelease(r)(l)
},
)(func(r R) TEA {
return f(r)(l)
})
}
}
}