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:
@ -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:]
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user