diff --git a/ioeither/http/builder/builder.go b/ioeither/http/builder/builder.go index fb8d381..270693c 100644 --- a/ioeither/http/builder/builder.go +++ b/ioeither/http/builder/builder.go @@ -82,6 +82,11 @@ var ( O.Of[IOE.IOEither[error, []byte]], Body.Set, ) + // WithBytes creates a [BuilderBuilder] for a request body using bytes + WithBytes = F.Flow2( + IOE.Of[error, []byte], + WithBody, + ) // WithContentType adds the [H.ContentType] header WithContentType = WithHeader(H.ContentType) // WithAuthorization adds the [H.Authorization] header diff --git a/lambda/y.go b/lambda/y.go index ef413c4..1074f77 100644 --- a/lambda/y.go +++ b/lambda/y.go @@ -15,16 +15,12 @@ package lambda -type ( - // RecFct is the function called recursively - RecFct[T, R any] func(T) R - - internalCombinator[T, R any] func(internalCombinator[T, R]) RecFct[T, R] -) - // Y is the Y-combinator based on https://dreamsongs.com/Files/WhyOfY.pdf -func Y[TRFRM ~func(RecFct[T, R]) RecFct[T, R], T, R any](f TRFRM) RecFct[T, R] { - g := func(h internalCombinator[T, R]) RecFct[T, R] { +func Y[TRFRM ~func(RecFct) RecFct, RecFct ~func(T) R, T, R any](f TRFRM) RecFct { + + type internalCombinator[RecFct ~func(T) R, T, R any] func(internalCombinator[RecFct, T, R]) RecFct + + g := func(h internalCombinator[RecFct, T, R]) RecFct { return func(t T) R { return f(h(h))(t) } diff --git a/lambda/y_test.go b/lambda/y_test.go index c4f4d56..bd9d7fa 100644 --- a/lambda/y_test.go +++ b/lambda/y_test.go @@ -16,12 +16,13 @@ package lambda import ( - "fmt" "testing" + + "github.com/stretchr/testify/assert" ) func TestFactorial(t *testing.T) { - fct := Y(func(r RecFct[int, int]) RecFct[int, int] { + fct := Y(func(r func(int) int) func(int) int { return func(n int) int { if n <= 0 { return 1 @@ -29,6 +30,5 @@ func TestFactorial(t *testing.T) { return n * r(n-1) } }) - - fmt.Println(fct(10)) + assert.Equal(t, 3628800, fct(10)) }