1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-10 22:31:32 +02:00

fix: consistent endomorphism

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-12-17 13:24:05 +01:00
parent 5fcd0b1595
commit e82575fe08
3 changed files with 27 additions and 11 deletions

View File

@@ -29,15 +29,11 @@ func Of[ENDO ~func(A) A, F ~func(A) A, A any](f F) ENDO {
}
func Identity[ENDO ~func(A) A, A any]() ENDO {
return func(a A) A {
return a
}
return Of[ENDO](F.Identity[A])
}
func Compose[ENDO ~func(A) A, A any](f1, f2 ENDO) ENDO {
return func(a A) A {
return F.Pipe2(a, f1, f2)
}
return Of[ENDO](F.Flow2(f1, f2))
}
// Semigroup for the Endomorphism where the `concat` operation is the usual function composition.

View File

@@ -38,6 +38,9 @@ var (
noField = O.None[string]()
// FormMonoid is the [M.Monoid] for the [FormEndomorphism]
FormMonoid = ENDO.Monoid[url.Values]()
// AtValues is a [L.Lens] that focusses on the values of a form field
AtValues = LRG.AtRecord[url.Values, []string]

View File

@@ -50,6 +50,9 @@ var (
defaultMethod = F.Constant(http.MethodGet)
// BuilderMonoid is the [M.Monoid] for the [BuilderEndomorphism]
BuilderMonoid = ENDO.Monoid[*Builder]()
// Url is a [L.Lens] for the URL
Url = L.MakeLensRef((*Builder).GetUrl, (*Builder).SetUrl)
// Method is a [L.Lens] for the HTTP method
@@ -67,15 +70,25 @@ var (
noBody = O.None[IOE.IOEither[error, []byte]]()
// WithMethod creates a [BuilderBuilder] for a certain method
WithMethod = Method.Set
WithMethod = F.Flow2(
Method.Set,
ENDO.Of[func(*Builder) *Builder],
)
// WithUrl creates a [BuilderBuilder] for a certain method
WithUrl = Url.Set
WithUrl = F.Flow2(
Url.Set,
ENDO.Of[func(*Builder) *Builder],
)
// WithHeaders creates a [BuilderBuilder] for a set of headers
WithHeaders = Headers.Set
WithHeaders = F.Flow2(
Headers.Set,
ENDO.Of[func(*Builder) *Builder],
)
// WithBody creates a [BuilderBuilder] for a request body
WithBody = F.Flow2(
WithBody = F.Flow3(
O.Of[IOE.IOEither[error, []byte]],
Body.Set,
ENDO.Of[func(*Builder) *Builder],
)
// WithContentType adds the content type header
WithContentType = WithHeader("Content-Type")
@@ -93,7 +106,11 @@ var (
Requester = (*Builder).Requester
// WithoutBody creates a [BuilderBuilder] to remove the body
WithoutBody = Body.Set(noBody)
WithoutBody = F.Pipe2(
noBody,
Body.Set,
ENDO.Of[func(*Builder) *Builder],
)
)
func (builder *Builder) clone() *Builder {