1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-06-17 00:07:49 +02:00

fix: name the endomorphism for the Y combinator

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-12-22 14:41:55 +01:00
parent 973138c822
commit 36eefbcd27
2 changed files with 9 additions and 3 deletions

View File

@ -66,6 +66,12 @@ func Reduce[A, B any](f func(B, A) B, initial B) func(NonEmptyArray[A]) B {
} }
} }
func ReduceRight[A, B any](f func(A, B) B, initial B) func(NonEmptyArray[A]) B {
return func(as NonEmptyArray[A]) B {
return array.ReduceRight(as, f, initial)
}
}
func Tail[A any](as NonEmptyArray[A]) []A { func Tail[A any](as NonEmptyArray[A]) []A {
return as[1:] return as[1:]
} }

View File

@ -16,11 +16,11 @@
package lambda package lambda
// Y is the Y-combinator based on https://dreamsongs.com/Files/WhyOfY.pdf // Y is the Y-combinator based on https://dreamsongs.com/Files/WhyOfY.pdf
func Y[TRFRM ~func(RecFct) RecFct, RecFct ~func(T) R, T, R any](f TRFRM) RecFct { func Y[Endo ~func(RecFct) RecFct, RecFct ~func(T) R, T, R any](f Endo) RecFct {
type internalCombinator[RecFct ~func(T) R, T, R any] func(internalCombinator[RecFct, T, R]) RecFct type internal[RecFct ~func(T) R, T, R any] func(internal[RecFct, T, R]) RecFct
g := func(h internalCombinator[RecFct, T, R]) RecFct { g := func(h internal[RecFct, T, R]) RecFct {
return func(t T) R { return func(t T) R {
return f(h(h))(t) return f(h(h))(t)
} }