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

fix: some smaller optimizations

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2024-02-01 09:08:31 +01:00
parent b077fed094
commit 668eb85aea
19 changed files with 1101 additions and 1085 deletions

View File

@ -344,7 +344,7 @@ func MonadFlap[FAB ~func(A) B, GFAB ~[]FAB, GB ~[]B, A, B any](fab GFAB, a A) GB
} }
func Flap[FAB ~func(A) B, GFAB ~[]FAB, GB ~[]B, A, B any](a A) func(GFAB) GB { func Flap[FAB ~func(A) B, GFAB ~[]FAB, GB ~[]B, A, B any](a A) func(GFAB) GB {
return F.Bind2nd(MonadFlap[FAB, GFAB, GB, A, B], a) return FC.Flap(Map[GFAB, GB], a)
} }
func Prepend[ENDO ~func(AS) AS, AS []A, A any](head A) ENDO { func Prepend[ENDO ~func(AS) AS, AS []A, A any](head A) ENDO {

View File

@ -64,7 +64,7 @@ func MonadMapTo[E, A, B any](fa Either[E, A], b B) Either[E, B] {
} }
func MapTo[E, A, B any](b B) func(Either[E, A]) Either[E, B] { func MapTo[E, A, B any](b B) func(Either[E, A]) Either[E, B] {
return F.Bind2nd(MonadMapTo[E, A, B], b) return Map[E](F.Constant1[A](b))
} }
func MonadMapLeft[E1, A, E2 any](fa Either[E1, A], f func(E1) E2) Either[E2, A] { func MonadMapLeft[E1, A, E2 any](fa Either[E1, A], f func(E1) E2) Either[E2, A] {
@ -106,11 +106,11 @@ func ChainOptionK[A, B, E any](onNone func() E) func(func(A) O.Option[B]) func(E
} }
func ChainTo[A, E, B any](mb Either[E, B]) func(Either[E, A]) Either[E, B] { func ChainTo[A, E, B any](mb Either[E, B]) func(Either[E, A]) Either[E, B] {
return F.Bind2nd(MonadChainTo[A, E, B], mb) return F.Constant1[Either[E, A]](mb)
} }
func Chain[E, A, B any](f func(a A) Either[E, B]) func(Either[E, A]) Either[E, B] { func Chain[E, A, B any](f func(a A) Either[E, B]) func(Either[E, A]) Either[E, B] {
return F.Bind2nd(MonadChain[E, A, B], f) return Fold(Left[B, E], f)
} }
func ChainFirst[E, A, B any](f func(a A) Either[E, B]) func(Either[E, A]) Either[E, A] { func ChainFirst[E, A, B any](f func(a A) Either[E, B]) func(Either[E, A]) Either[E, A] {
@ -251,7 +251,7 @@ func MonadFlap[E, B, A any](fab Either[E, func(A) B], a A) Either[E, B] {
} }
func Flap[E, B, A any](a A) func(Either[E, func(A) B]) Either[E, B] { func Flap[E, B, A any](a A) func(Either[E, func(A) B]) Either[E, B] {
return F.Bind2nd(MonadFlap[E, B, A], a) return FC.Flap(Map[E, func(A) B, B], a)
} }
func MonadAlt[E, A any](fa Either[E, A], that L.Lazy[Either[E, A]]) Either[E, A] { func MonadAlt[E, A any](fa Either[E, A], that L.Lazy[Either[E, A]]) Either[E, A] {

View File

@ -3,449 +3,453 @@
// 2024-01-31 21:45:01.6437619 +0100 CET m=+0.032758901 // 2024-01-31 21:45:01.6437619 +0100 CET m=+0.032758901
package function package function
// Combinations for a total of 1 arguments // Combinations for a total of 1 arguments
// Bind1of1 takes a function with 1 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function. // Bind1of1 takes a function with 1 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
// The return value of is a function with the remaining 0 parameters at positions [] of the original function. // The return value of is a function with the remaining 0 parameters at positions [] of the original function.
func Bind1of1[F ~func(T1) R, T1, R any](f F) func(T1) func() R { func Bind1of1[F ~func(T1) R, T1, R any](f F) func(T1) func() R {
return func(t1 T1) func() R { return func(t1 T1) func() R {
return func() R { return func() R {
return f(t1) return f(t1)
} }
} }
} }
// Ignore1of1 takes a function with 0 parameters and returns a new function with 1 parameters that will ignore the values at positions [1] and pass the remaining 0 parameters to the original function // Ignore1of1 takes a function with 0 parameters and returns a new function with 1 parameters that will ignore the values at positions [1] and pass the remaining 0 parameters to the original function
func Ignore1of1[T1 any, F ~func() R, R any](f F) func(T1) R { func Ignore1of1[T1 any, F ~func() R, R any](f F) func(T1) R {
return func(t1 T1) R { return func(t1 T1) R {
return f() return f()
} }
} }
// Combinations for a total of 2 arguments // Combinations for a total of 2 arguments
// Bind1of2 takes a function with 2 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function. // Bind1of2 takes a function with 2 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [2] of the original function. // The return value of is a function with the remaining 1 parameters at positions [2] of the original function.
func Bind1of2[F ~func(T1, T2) R, T1, T2, R any](f F) func(T1) func(T2) R { func Bind1of2[F ~func(T1, T2) R, T1, T2, R any](f F) func(T1) func(T2) R {
return func(t1 T1) func(T2) R { return func(t1 T1) func(T2) R {
return func(t2 T2) R { return func(t2 T2) R {
return f(t1, t2) return f(t1, t2)
} }
} }
} }
// Ignore1of2 takes a function with 1 parameters and returns a new function with 2 parameters that will ignore the values at positions [1] and pass the remaining 1 parameters to the original function // Ignore1of2 takes a function with 1 parameters and returns a new function with 2 parameters that will ignore the values at positions [1] and pass the remaining 1 parameters to the original function
func Ignore1of2[T1 any, F ~func(T2) R, T2, R any](f F) func(T1, T2) R { func Ignore1of2[T1 any, F ~func(T2) R, T2, R any](f F) func(T1, T2) R {
return func(t1 T1, t2 T2) R { return func(t1 T1, t2 T2) R {
return f(t2) return f(t2)
} }
} }
// Bind2of2 takes a function with 2 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [2] of the original function. // Bind2of2 takes a function with 2 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [2] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [1] of the original function. // The return value of is a function with the remaining 1 parameters at positions [1] of the original function.
func Bind2of2[F ~func(T1, T2) R, T1, T2, R any](f F) func(T2) func(T1) R { func Bind2of2[F ~func(T1, T2) R, T1, T2, R any](f F) func(T2) func(T1) R {
return func(t2 T2) func(T1) R { return func(t2 T2) func(T1) R {
return func(t1 T1) R { return func(t1 T1) R {
return f(t1, t2) return f(t1, t2)
} }
} }
} }
// Ignore2of2 takes a function with 1 parameters and returns a new function with 2 parameters that will ignore the values at positions [2] and pass the remaining 1 parameters to the original function // Ignore2of2 takes a function with 1 parameters and returns a new function with 2 parameters that will ignore the values at positions [2] and pass the remaining 1 parameters to the original function
func Ignore2of2[T2 any, F ~func(T1) R, T1, R any](f F) func(T1, T2) R { func Ignore2of2[T2 any, F ~func(T1) R, T1, R any](f F) func(T1, T2) R {
return func(t1 T1, t2 T2) R { return func(t1 T1, t2 T2) R {
return f(t1) return f(t1)
} }
} }
// Bind12of2 takes a function with 2 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 2] of the original function. // Bind12of2 takes a function with 2 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 2] of the original function.
// The return value of is a function with the remaining 0 parameters at positions [] of the original function. // The return value of is a function with the remaining 0 parameters at positions [] of the original function.
func Bind12of2[F ~func(T1, T2) R, T1, T2, R any](f F) func(T1, T2) func() R { func Bind12of2[F ~func(T1, T2) R, T1, T2, R any](f F) func(T1, T2) func() R {
return func(t1 T1, t2 T2) func() R { return func(t1 T1, t2 T2) func() R {
return func() R { return func() R {
return f(t1, t2) return f(t1, t2)
} }
} }
} }
// Ignore12of2 takes a function with 0 parameters and returns a new function with 2 parameters that will ignore the values at positions [1, 2] and pass the remaining 0 parameters to the original function // Ignore12of2 takes a function with 0 parameters and returns a new function with 2 parameters that will ignore the values at positions [1, 2] and pass the remaining 0 parameters to the original function
func Ignore12of2[T1, T2 any, F ~func() R, R any](f F) func(T1, T2) R { func Ignore12of2[T1, T2 any, F ~func() R, R any](f F) func(T1, T2) R {
return func(t1 T1, t2 T2) R { return func(t1 T1, t2 T2) R {
return f() return f()
} }
} }
// Combinations for a total of 3 arguments // Combinations for a total of 3 arguments
// Bind1of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function. // Bind1of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [2, 3] of the original function. // The return value of is a function with the remaining 2 parameters at positions [2, 3] of the original function.
func Bind1of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1) func(T2, T3) R { func Bind1of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1) func(T2, T3) R {
return func(t1 T1) func(T2, T3) R { return func(t1 T1) func(T2, T3) R {
return func(t2 T2, t3 T3) R { return func(t2 T2, t3 T3) R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
} }
// Ignore1of3 takes a function with 2 parameters and returns a new function with 3 parameters that will ignore the values at positions [1] and pass the remaining 2 parameters to the original function // Ignore1of3 takes a function with 2 parameters and returns a new function with 3 parameters that will ignore the values at positions [1] and pass the remaining 2 parameters to the original function
func Ignore1of3[T1 any, F ~func(T2, T3) R, T2, T3, R any](f F) func(T1, T2, T3) R { func Ignore1of3[T1 any, F ~func(T2, T3) R, T2, T3, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f(t2, t3) return f(t2, t3)
} }
} }
// Bind2of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [2] of the original function. // Bind2of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [2] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [1, 3] of the original function. // The return value of is a function with the remaining 2 parameters at positions [1, 3] of the original function.
func Bind2of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T2) func(T1, T3) R { func Bind2of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T2) func(T1, T3) R {
return func(t2 T2) func(T1, T3) R { return func(t2 T2) func(T1, T3) R {
return func(t1 T1, t3 T3) R { return func(t1 T1, t3 T3) R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
} }
// Ignore2of3 takes a function with 2 parameters and returns a new function with 3 parameters that will ignore the values at positions [2] and pass the remaining 2 parameters to the original function // Ignore2of3 takes a function with 2 parameters and returns a new function with 3 parameters that will ignore the values at positions [2] and pass the remaining 2 parameters to the original function
func Ignore2of3[T2 any, F ~func(T1, T3) R, T1, T3, R any](f F) func(T1, T2, T3) R { func Ignore2of3[T2 any, F ~func(T1, T3) R, T1, T3, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f(t1, t3) return f(t1, t3)
} }
} }
// Bind3of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [3] of the original function. // Bind3of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [3] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [1, 2] of the original function. // The return value of is a function with the remaining 2 parameters at positions [1, 2] of the original function.
func Bind3of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T3) func(T1, T2) R { func Bind3of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T3) func(T1, T2) R {
return func(t3 T3) func(T1, T2) R { return func(t3 T3) func(T1, T2) R {
return func(t1 T1, t2 T2) R { return func(t1 T1, t2 T2) R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
} }
// Ignore3of3 takes a function with 2 parameters and returns a new function with 3 parameters that will ignore the values at positions [3] and pass the remaining 2 parameters to the original function // Ignore3of3 takes a function with 2 parameters and returns a new function with 3 parameters that will ignore the values at positions [3] and pass the remaining 2 parameters to the original function
func Ignore3of3[T3 any, F ~func(T1, T2) R, T1, T2, R any](f F) func(T1, T2, T3) R { func Ignore3of3[T3 any, F ~func(T1, T2) R, T1, T2, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f(t1, t2) return f(t1, t2)
} }
} }
// Bind12of3 takes a function with 3 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 2] of the original function. // Bind12of3 takes a function with 3 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 2] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [3] of the original function. // The return value of is a function with the remaining 1 parameters at positions [3] of the original function.
func Bind12of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T2) func(T3) R { func Bind12of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T2) func(T3) R {
return func(t1 T1, t2 T2) func(T3) R { return func(t1 T1, t2 T2) func(T3) R {
return func(t3 T3) R { return func(t3 T3) R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
} }
// Ignore12of3 takes a function with 1 parameters and returns a new function with 3 parameters that will ignore the values at positions [1, 2] and pass the remaining 1 parameters to the original function // Ignore12of3 takes a function with 1 parameters and returns a new function with 3 parameters that will ignore the values at positions [1, 2] and pass the remaining 1 parameters to the original function
func Ignore12of3[T1, T2 any, F ~func(T3) R, T3, R any](f F) func(T1, T2, T3) R { func Ignore12of3[T1, T2 any, F ~func(T3) R, T3, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f(t3) return f(t3)
} }
} }
// Bind13of3 takes a function with 3 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 3] of the original function. // Bind13of3 takes a function with 3 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 3] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [2] of the original function. // The return value of is a function with the remaining 1 parameters at positions [2] of the original function.
func Bind13of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T3) func(T2) R { func Bind13of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T3) func(T2) R {
return func(t1 T1, t3 T3) func(T2) R { return func(t1 T1, t3 T3) func(T2) R {
return func(t2 T2) R { return func(t2 T2) R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
} }
// Ignore13of3 takes a function with 1 parameters and returns a new function with 3 parameters that will ignore the values at positions [1, 3] and pass the remaining 1 parameters to the original function // Ignore13of3 takes a function with 1 parameters and returns a new function with 3 parameters that will ignore the values at positions [1, 3] and pass the remaining 1 parameters to the original function
func Ignore13of3[T1, T3 any, F ~func(T2) R, T2, R any](f F) func(T1, T2, T3) R { func Ignore13of3[T1, T3 any, F ~func(T2) R, T2, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f(t2) return f(t2)
} }
} }
// Bind23of3 takes a function with 3 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [2, 3] of the original function. // Bind23of3 takes a function with 3 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [2, 3] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [1] of the original function. // The return value of is a function with the remaining 1 parameters at positions [1] of the original function.
func Bind23of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T2, T3) func(T1) R { func Bind23of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T2, T3) func(T1) R {
return func(t2 T2, t3 T3) func(T1) R { return func(t2 T2, t3 T3) func(T1) R {
return func(t1 T1) R { return func(t1 T1) R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
} }
// Ignore23of3 takes a function with 1 parameters and returns a new function with 3 parameters that will ignore the values at positions [2, 3] and pass the remaining 1 parameters to the original function // Ignore23of3 takes a function with 1 parameters and returns a new function with 3 parameters that will ignore the values at positions [2, 3] and pass the remaining 1 parameters to the original function
func Ignore23of3[T2, T3 any, F ~func(T1) R, T1, R any](f F) func(T1, T2, T3) R { func Ignore23of3[T2, T3 any, F ~func(T1) R, T1, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f(t1) return f(t1)
} }
} }
// Bind123of3 takes a function with 3 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 2, 3] of the original function. // Bind123of3 takes a function with 3 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 2, 3] of the original function.
// The return value of is a function with the remaining 0 parameters at positions [] of the original function. // The return value of is a function with the remaining 0 parameters at positions [] of the original function.
func Bind123of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T2, T3) func() R { func Bind123of3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T2, T3) func() R {
return func(t1 T1, t2 T2, t3 T3) func() R { return func(t1 T1, t2 T2, t3 T3) func() R {
return func() R { return func() R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
} }
// Ignore123of3 takes a function with 0 parameters and returns a new function with 3 parameters that will ignore the values at positions [1, 2, 3] and pass the remaining 0 parameters to the original function // Ignore123of3 takes a function with 0 parameters and returns a new function with 3 parameters that will ignore the values at positions [1, 2, 3] and pass the remaining 0 parameters to the original function
func Ignore123of3[T1, T2, T3 any, F ~func() R, R any](f F) func(T1, T2, T3) R { func Ignore123of3[T1, T2, T3 any, F ~func() R, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f() return f()
} }
} }
// Combinations for a total of 4 arguments // Combinations for a total of 4 arguments
// Bind1of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function. // Bind1of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
// The return value of is a function with the remaining 3 parameters at positions [2, 3, 4] of the original function. // The return value of is a function with the remaining 3 parameters at positions [2, 3, 4] of the original function.
func Bind1of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1) func(T2, T3, T4) R { func Bind1of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1) func(T2, T3, T4) R {
return func(t1 T1) func(T2, T3, T4) R { return func(t1 T1) func(T2, T3, T4) R {
return func(t2 T2, t3 T3, t4 T4) R { return func(t2 T2, t3 T3, t4 T4) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore1of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [1] and pass the remaining 3 parameters to the original function // Ignore1of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [1] and pass the remaining 3 parameters to the original function
func Ignore1of4[T1 any, F ~func(T2, T3, T4) R, T2, T3, T4, R any](f F) func(T1, T2, T3, T4) R { func Ignore1of4[T1 any, F ~func(T2, T3, T4) R, T2, T3, T4, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t2, t3, t4) return f(t2, t3, t4)
} }
} }
// Bind2of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [2] of the original function. // Bind2of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [2] of the original function.
// The return value of is a function with the remaining 3 parameters at positions [1, 3, 4] of the original function. // The return value of is a function with the remaining 3 parameters at positions [1, 3, 4] of the original function.
func Bind2of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2) func(T1, T3, T4) R { func Bind2of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2) func(T1, T3, T4) R {
return func(t2 T2) func(T1, T3, T4) R { return func(t2 T2) func(T1, T3, T4) R {
return func(t1 T1, t3 T3, t4 T4) R { return func(t1 T1, t3 T3, t4 T4) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore2of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [2] and pass the remaining 3 parameters to the original function // Ignore2of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [2] and pass the remaining 3 parameters to the original function
func Ignore2of4[T2 any, F ~func(T1, T3, T4) R, T1, T3, T4, R any](f F) func(T1, T2, T3, T4) R { func Ignore2of4[T2 any, F ~func(T1, T3, T4) R, T1, T3, T4, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t1, t3, t4) return f(t1, t3, t4)
} }
} }
// Bind3of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [3] of the original function. // Bind3of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [3] of the original function.
// The return value of is a function with the remaining 3 parameters at positions [1, 2, 4] of the original function. // The return value of is a function with the remaining 3 parameters at positions [1, 2, 4] of the original function.
func Bind3of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T3) func(T1, T2, T4) R { func Bind3of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T3) func(T1, T2, T4) R {
return func(t3 T3) func(T1, T2, T4) R { return func(t3 T3) func(T1, T2, T4) R {
return func(t1 T1, t2 T2, t4 T4) R { return func(t1 T1, t2 T2, t4 T4) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore3of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [3] and pass the remaining 3 parameters to the original function // Ignore3of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [3] and pass the remaining 3 parameters to the original function
func Ignore3of4[T3 any, F ~func(T1, T2, T4) R, T1, T2, T4, R any](f F) func(T1, T2, T3, T4) R { func Ignore3of4[T3 any, F ~func(T1, T2, T4) R, T1, T2, T4, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t1, t2, t4) return f(t1, t2, t4)
} }
} }
// Bind4of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [4] of the original function. // Bind4of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [4] of the original function.
// The return value of is a function with the remaining 3 parameters at positions [1, 2, 3] of the original function. // The return value of is a function with the remaining 3 parameters at positions [1, 2, 3] of the original function.
func Bind4of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T4) func(T1, T2, T3) R { func Bind4of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T4) func(T1, T2, T3) R {
return func(t4 T4) func(T1, T2, T3) R { return func(t4 T4) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R { return func(t1 T1, t2 T2, t3 T3) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore4of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [4] and pass the remaining 3 parameters to the original function // Ignore4of4 takes a function with 3 parameters and returns a new function with 4 parameters that will ignore the values at positions [4] and pass the remaining 3 parameters to the original function
func Ignore4of4[T4 any, F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T2, T3, T4) R { func Ignore4of4[T4 any, F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t1, t2, t3) return f(t1, t2, t3)
} }
} }
// Bind12of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 2] of the original function. // Bind12of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 2] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [3, 4] of the original function. // The return value of is a function with the remaining 2 parameters at positions [3, 4] of the original function.
func Bind12of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2) func(T3, T4) R { func Bind12of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2) func(T3, T4) R {
return func(t1 T1, t2 T2) func(T3, T4) R { return func(t1 T1, t2 T2) func(T3, T4) R {
return func(t3 T3, t4 T4) R { return func(t3 T3, t4 T4) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore12of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2] and pass the remaining 2 parameters to the original function // Ignore12of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2] and pass the remaining 2 parameters to the original function
func Ignore12of4[T1, T2 any, F ~func(T3, T4) R, T3, T4, R any](f F) func(T1, T2, T3, T4) R { func Ignore12of4[T1, T2 any, F ~func(T3, T4) R, T3, T4, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t3, t4) return f(t3, t4)
} }
} }
// Bind13of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 3] of the original function. // Bind13of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 3] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [2, 4] of the original function. // The return value of is a function with the remaining 2 parameters at positions [2, 4] of the original function.
func Bind13of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T3) func(T2, T4) R { func Bind13of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T3) func(T2, T4) R {
return func(t1 T1, t3 T3) func(T2, T4) R { return func(t1 T1, t3 T3) func(T2, T4) R {
return func(t2 T2, t4 T4) R { return func(t2 T2, t4 T4) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore13of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 3] and pass the remaining 2 parameters to the original function // Ignore13of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 3] and pass the remaining 2 parameters to the original function
func Ignore13of4[T1, T3 any, F ~func(T2, T4) R, T2, T4, R any](f F) func(T1, T2, T3, T4) R { func Ignore13of4[T1, T3 any, F ~func(T2, T4) R, T2, T4, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t2, t4) return f(t2, t4)
} }
} }
// Bind14of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 4] of the original function. // Bind14of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [1, 4] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [2, 3] of the original function. // The return value of is a function with the remaining 2 parameters at positions [2, 3] of the original function.
func Bind14of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T4) func(T2, T3) R { func Bind14of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T4) func(T2, T3) R {
return func(t1 T1, t4 T4) func(T2, T3) R { return func(t1 T1, t4 T4) func(T2, T3) R {
return func(t2 T2, t3 T3) R { return func(t2 T2, t3 T3) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore14of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 4] and pass the remaining 2 parameters to the original function // Ignore14of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 4] and pass the remaining 2 parameters to the original function
func Ignore14of4[T1, T4 any, F ~func(T2, T3) R, T2, T3, R any](f F) func(T1, T2, T3, T4) R { func Ignore14of4[T1, T4 any, F ~func(T2, T3) R, T2, T3, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t2, t3) return f(t2, t3)
} }
} }
// Bind23of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [2, 3] of the original function. // Bind23of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [2, 3] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [1, 4] of the original function. // The return value of is a function with the remaining 2 parameters at positions [1, 4] of the original function.
func Bind23of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2, T3) func(T1, T4) R { func Bind23of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2, T3) func(T1, T4) R {
return func(t2 T2, t3 T3) func(T1, T4) R { return func(t2 T2, t3 T3) func(T1, T4) R {
return func(t1 T1, t4 T4) R { return func(t1 T1, t4 T4) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore23of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [2, 3] and pass the remaining 2 parameters to the original function // Ignore23of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [2, 3] and pass the remaining 2 parameters to the original function
func Ignore23of4[T2, T3 any, F ~func(T1, T4) R, T1, T4, R any](f F) func(T1, T2, T3, T4) R { func Ignore23of4[T2, T3 any, F ~func(T1, T4) R, T1, T4, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t1, t4) return f(t1, t4)
} }
} }
// Bind24of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [2, 4] of the original function. // Bind24of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [2, 4] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [1, 3] of the original function. // The return value of is a function with the remaining 2 parameters at positions [1, 3] of the original function.
func Bind24of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2, T4) func(T1, T3) R { func Bind24of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2, T4) func(T1, T3) R {
return func(t2 T2, t4 T4) func(T1, T3) R { return func(t2 T2, t4 T4) func(T1, T3) R {
return func(t1 T1, t3 T3) R { return func(t1 T1, t3 T3) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore24of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [2, 4] and pass the remaining 2 parameters to the original function // Ignore24of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [2, 4] and pass the remaining 2 parameters to the original function
func Ignore24of4[T2, T4 any, F ~func(T1, T3) R, T1, T3, R any](f F) func(T1, T2, T3, T4) R { func Ignore24of4[T2, T4 any, F ~func(T1, T3) R, T1, T3, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t1, t3) return f(t1, t3)
} }
} }
// Bind34of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [3, 4] of the original function. // Bind34of4 takes a function with 4 parameters and returns a new function with 2 parameters that will bind these parameters to the positions [3, 4] of the original function.
// The return value of is a function with the remaining 2 parameters at positions [1, 2] of the original function. // The return value of is a function with the remaining 2 parameters at positions [1, 2] of the original function.
func Bind34of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T3, T4) func(T1, T2) R { func Bind34of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T3, T4) func(T1, T2) R {
return func(t3 T3, t4 T4) func(T1, T2) R { return func(t3 T3, t4 T4) func(T1, T2) R {
return func(t1 T1, t2 T2) R { return func(t1 T1, t2 T2) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore34of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [3, 4] and pass the remaining 2 parameters to the original function // Ignore34of4 takes a function with 2 parameters and returns a new function with 4 parameters that will ignore the values at positions [3, 4] and pass the remaining 2 parameters to the original function
func Ignore34of4[T3, T4 any, F ~func(T1, T2) R, T1, T2, R any](f F) func(T1, T2, T3, T4) R { func Ignore34of4[T3, T4 any, F ~func(T1, T2) R, T1, T2, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t1, t2) return f(t1, t2)
} }
} }
// Bind123of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 2, 3] of the original function. // Bind123of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 2, 3] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [4] of the original function. // The return value of is a function with the remaining 1 parameters at positions [4] of the original function.
func Bind123of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2, T3) func(T4) R { func Bind123of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2, T3) func(T4) R {
return func(t1 T1, t2 T2, t3 T3) func(T4) R { return func(t1 T1, t2 T2, t3 T3) func(T4) R {
return func(t4 T4) R { return func(t4 T4) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore123of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2, 3] and pass the remaining 1 parameters to the original function // Ignore123of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2, 3] and pass the remaining 1 parameters to the original function
func Ignore123of4[T1, T2, T3 any, F ~func(T4) R, T4, R any](f F) func(T1, T2, T3, T4) R { func Ignore123of4[T1, T2, T3 any, F ~func(T4) R, T4, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t4) return f(t4)
} }
} }
// Bind124of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 2, 4] of the original function. // Bind124of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 2, 4] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [3] of the original function. // The return value of is a function with the remaining 1 parameters at positions [3] of the original function.
func Bind124of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2, T4) func(T3) R { func Bind124of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2, T4) func(T3) R {
return func(t1 T1, t2 T2, t4 T4) func(T3) R { return func(t1 T1, t2 T2, t4 T4) func(T3) R {
return func(t3 T3) R { return func(t3 T3) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore124of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2, 4] and pass the remaining 1 parameters to the original function // Ignore124of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2, 4] and pass the remaining 1 parameters to the original function
func Ignore124of4[T1, T2, T4 any, F ~func(T3) R, T3, R any](f F) func(T1, T2, T3, T4) R { func Ignore124of4[T1, T2, T4 any, F ~func(T3) R, T3, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t3) return f(t3)
} }
} }
// Bind134of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 3, 4] of the original function. // Bind134of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [1, 3, 4] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [2] of the original function. // The return value of is a function with the remaining 1 parameters at positions [2] of the original function.
func Bind134of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T3, T4) func(T2) R { func Bind134of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T3, T4) func(T2) R {
return func(t1 T1, t3 T3, t4 T4) func(T2) R { return func(t1 T1, t3 T3, t4 T4) func(T2) R {
return func(t2 T2) R { return func(t2 T2) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore134of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 3, 4] and pass the remaining 1 parameters to the original function // Ignore134of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 3, 4] and pass the remaining 1 parameters to the original function
func Ignore134of4[T1, T3, T4 any, F ~func(T2) R, T2, R any](f F) func(T1, T2, T3, T4) R { func Ignore134of4[T1, T3, T4 any, F ~func(T2) R, T2, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t2) return f(t2)
} }
} }
// Bind234of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [2, 3, 4] of the original function. // Bind234of4 takes a function with 4 parameters and returns a new function with 3 parameters that will bind these parameters to the positions [2, 3, 4] of the original function.
// The return value of is a function with the remaining 1 parameters at positions [1] of the original function. // The return value of is a function with the remaining 1 parameters at positions [1] of the original function.
func Bind234of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2, T3, T4) func(T1) R { func Bind234of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T2, T3, T4) func(T1) R {
return func(t2 T2, t3 T3, t4 T4) func(T1) R { return func(t2 T2, t3 T3, t4 T4) func(T1) R {
return func(t1 T1) R { return func(t1 T1) R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore234of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [2, 3, 4] and pass the remaining 1 parameters to the original function // Ignore234of4 takes a function with 1 parameters and returns a new function with 4 parameters that will ignore the values at positions [2, 3, 4] and pass the remaining 1 parameters to the original function
func Ignore234of4[T2, T3, T4 any, F ~func(T1) R, T1, R any](f F) func(T1, T2, T3, T4) R { func Ignore234of4[T2, T3, T4 any, F ~func(T1) R, T1, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f(t1) return f(t1)
} }
} }
// Bind1234of4 takes a function with 4 parameters and returns a new function with 4 parameters that will bind these parameters to the positions [1, 2, 3, 4] of the original function. // Bind1234of4 takes a function with 4 parameters and returns a new function with 4 parameters that will bind these parameters to the positions [1, 2, 3, 4] of the original function.
// The return value of is a function with the remaining 0 parameters at positions [] of the original function. // The return value of is a function with the remaining 0 parameters at positions [] of the original function.
func Bind1234of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2, T3, T4) func() R { func Bind1234of4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(T1, T2, T3, T4) func() R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) func() R { return func(t1 T1, t2 T2, t3 T3, t4 T4) func() R {
return func() R { return func() R {
return f(t1, t2, t3, t4) return f(t1, t2, t3, t4)
} }
} }
} }
// Ignore1234of4 takes a function with 0 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2, 3, 4] and pass the remaining 0 parameters to the original function // Ignore1234of4 takes a function with 0 parameters and returns a new function with 4 parameters that will ignore the values at positions [1, 2, 3, 4] and pass the remaining 0 parameters to the original function
func Ignore1234of4[T1, T2, T3, T4 any, F ~func() R, R any](f F) func(T1, T2, T3, T4) R { func Ignore1234of4[T1, T2, T3, T4 any, F ~func() R, R any](f F) func(T1, T2, T3, T4) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4) R { return func(t1 T1, t2 T2, t3 T3, t4 T4) R {
return f() return f()
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -58,5 +58,5 @@ func MonadFlap[GAB ~func(A) B, A, B any](fab GAB, a A) B {
} }
func Flap[GAB ~func(A) B, B, A any](a A) func(GAB) B { func Flap[GAB ~func(A) B, B, A any](a A) func(GAB) B {
return F.Bind2nd(MonadFlap[GAB, A, B], a) return FC.Flap(Map[func(GAB) B, GAB, B], a)
} }

View File

@ -19,13 +19,6 @@ import (
F "github.com/IBM/fp-go/function" F "github.com/IBM/fp-go/function"
) )
// HKTFGA = HKT<F, HKT<G, A>>
// HKTFGB = HKT<F, HKT<G, B>>
// HKTFGAB = HKT<F, HKT<G, (a: A) => B>>
// HKTGA = HKT<G, A>
// HKTGB = HKT<G, B>
// HKTGAB = HKT<G, (a: A) => B>
func MonadAp[HKTGA, HKTGB, HKTGAB, HKTFGAB, HKTFGGAB, HKTFGA, HKTFGB any]( func MonadAp[HKTGA, HKTGB, HKTGAB, HKTFGAB, HKTFGGAB, HKTFGA, HKTFGB any](
fap func(HKTFGGAB, HKTFGA) HKTFGB, fap func(HKTFGGAB, HKTFGA) HKTFGB,
fmap func(HKTFGAB, func(HKTGAB) func(HKTGA) HKTGB) HKTFGGAB, fmap func(HKTFGAB, func(HKTGAB) func(HKTGA) HKTGB) HKTFGGAB,
@ -37,6 +30,19 @@ func MonadAp[HKTGA, HKTGB, HKTGAB, HKTFGAB, HKTFGGAB, HKTFGA, HKTFGB any](
return fap(fmap(fab, F.Bind1st(F.Bind1st[HKTGAB, HKTGA, HKTGB], gap)), fa) return fap(fmap(fab, F.Bind1st(F.Bind1st[HKTGAB, HKTGA, HKTGB], gap)), fa)
} }
func Ap[HKTGA, HKTGB, HKTGAB, HKTFGAB, HKTFGGAB, HKTFGA, HKTFGB any](
fap func(HKTFGA) func(HKTFGGAB) HKTFGB,
fmap func(func(HKTGAB) func(HKTGA) HKTGB) func(HKTFGAB) HKTFGGAB,
gap func(HKTGA) func(HKTGAB) HKTGB,
fa HKTFGA) func(HKTFGAB) HKTFGB {
return F.Flow2(
fmap(F.Flip(gap)),
fap(fa),
)
}
// func Ap[HKTGA, HKTGB, HKTGAB, HKTFGAB, HKTFGGAB, HKTFGA, HKTFGB any]( // func Ap[HKTGA, HKTGB, HKTGAB, HKTFGAB, HKTFGGAB, HKTFGA, HKTFGB any](
// fap func(HKTFGA) func(HKTFGGAB) HKTFGB, // fap func(HKTFGA) func(HKTFGGAB) HKTFGB,
// fmap func(func(HKTGAB) func(HKTGA) HKTGB) func(HKTFGAB) HKTFGGAB, // fmap func(func(HKTGAB) func(HKTGA) HKTGB) func(HKTFGAB) HKTFGGAB,

View File

@ -78,22 +78,21 @@ func MonadChain[E, A, B, HKTFA, HKTFB any](
return fchain(ma, ET.Fold(F.Flow2(ET.Left[B, E], fof), f)) return fchain(ma, ET.Fold(F.Flow2(ET.Left[B, E], fof), f))
} }
// func(fa func(R) T.Task[ET.Either[E, func(A) B]], f func(ET.Either[E, func(A) B]) func(ET.Either[E, A]) ET.Either[E, B]) GEFAB
// HKTFA = HKT[Either[E, A]]
// HKTFB = HKT[Either[E, B]]
// HKTFAB = HKT[Either[E, func(A)B]]
func MonadAp[E, A, B, HKTFAB, HKTFGAB, HKTFA, HKTFB any]( func MonadAp[E, A, B, HKTFAB, HKTFGAB, HKTFA, HKTFB any](
fap func(HKTFGAB, HKTFA) HKTFB, fap func(HKTFGAB, HKTFA) HKTFB,
fmap func(HKTFAB, func(ET.Either[E, func(A) B]) func(ET.Either[E, A]) ET.Either[E, B]) HKTFGAB, fmap func(HKTFAB, func(ET.Either[E, func(A) B]) func(ET.Either[E, A]) ET.Either[E, B]) HKTFGAB,
fab HKTFAB, fab HKTFAB,
fa HKTFA) HKTFB { fa HKTFA) HKTFB {
// HKTGA = ET.Either[E, A]
// HKTGB = ET.Either[E, B]
// HKTGAB = ET.Either[E, func(a A) B]
return apply.MonadAp(fap, fmap, ET.MonadAp[B, E, A], fab, fa) return apply.MonadAp(fap, fmap, ET.MonadAp[B, E, A], fab, fa)
} }
func Ap[E, A, B, HKTFAB, HKTFGAB, HKTFA, HKTFB any](
fap func(HKTFA) func(HKTFGAB) HKTFB,
fmap func(func(ET.Either[E, func(A) B]) func(ET.Either[E, A]) ET.Either[E, B]) func(HKTFAB) HKTFGAB,
fa HKTFA) func(HKTFAB) HKTFB {
return apply.Ap(fap, fmap, ET.Ap[B, E, A], fa)
}
func Right[E, A, HKTA any](fof func(ET.Either[E, A]) HKTA, a A) HKTA { func Right[E, A, HKTA any](fof func(ET.Either[E, A]) HKTA, a A) HKTA {
return F.Pipe2(a, ET.Right[E, A], fof) return F.Pipe2(a, ET.Right[E, A], fof)
} }

View File

@ -15,23 +15,24 @@
package functor package functor
func flap[FAB ~func(A) B, A, B any](a A) func(FAB) B {
return func(f FAB) B {
return f(a)
}
}
func MonadFlap[FAB ~func(A) B, A, B, HKTFAB, HKTB any]( func MonadFlap[FAB ~func(A) B, A, B, HKTFAB, HKTB any](
fmap func(HKTFAB, func(FAB) B) HKTB, fmap func(HKTFAB, func(FAB) B) HKTB,
fab HKTFAB, fab HKTFAB,
a A, a A,
) HKTB { ) HKTB {
return fmap(fab, func(f FAB) B { return fmap(fab, flap[FAB, A, B](a))
return f(a)
})
} }
func Flap[FAB ~func(A) B, A, B, HKTFAB, HKTB any]( func Flap[FAB ~func(A) B, A, B, HKTFAB, HKTB any](
fmap func(HKTFAB, func(FAB) B) HKTB, fmap func(func(FAB) B) func(HKTFAB) HKTB,
a A, a A,
) func(HKTFAB) HKTB { ) func(HKTFAB) HKTB {
return func(fab HKTFAB) HKTB { return fmap(flap[FAB, A, B](a))
return MonadFlap(fmap, fab, a)
}
} }

View File

@ -33,11 +33,7 @@ func Map[A, B, HKTGA, HKTGB, HKTFGA, HKTFGB any](
fmap func(func(HKTGA) HKTGB) func(HKTFGA) HKTFGB, fmap func(func(HKTGA) HKTGB) func(HKTFGA) HKTFGB,
gmap func(func(A) B) func(HKTGA) HKTGB, gmap func(func(A) B) func(HKTGA) HKTGB,
f func(A) B) func(HKTFGA) HKTFGB { f func(A) B) func(HKTFGA) HKTFGB {
return F.Pipe2( return fmap(gmap(f))
f,
gmap,
fmap,
)
} }
func MonadLet[S1, S2, B, HKTS1, HKTS2 any]( func MonadLet[S1, S2, B, HKTS1, HKTS2 any](

View File

@ -67,6 +67,13 @@ func MonadAp[A, B, HKTFAB, HKTFGAB, HKTFA, HKTFB any](
return apply.MonadAp(fap, fmap, O.MonadAp[B, A], fab, fa) return apply.MonadAp(fap, fmap, O.MonadAp[B, A], fab, fa)
} }
func Ap[A, B, HKTFAB, HKTFGAB, HKTFA, HKTFB any](
fap func(HKTFA) func(HKTFGAB) HKTFB,
fmap func(func(O.Option[func(A) B]) func(O.Option[A]) O.Option[B]) func(HKTFAB) HKTFGAB,
fa HKTFA) func(HKTFAB) HKTFB {
return apply.Ap(fap, fmap, O.Ap[B, A], fa)
}
func MatchE[A, HKTEA, HKTB any](mchain func(HKTEA, func(O.Option[A]) HKTB) HKTB, onNone func() HKTB, onSome func(A) HKTB) func(HKTEA) HKTB { func MatchE[A, HKTEA, HKTB any](mchain func(HKTEA, func(O.Option[A]) HKTB) HKTB, onNone func() HKTB, onSome func(A) HKTB) func(HKTEA) HKTB {
return F.Bind2nd(mchain, O.Fold(onNone, onSome)) return F.Bind2nd(mchain, O.Fold(onNone, onSome))
} }

View File

@ -53,7 +53,7 @@ func MonadOf[GA ~func() A, A any](a A) GA {
func MonadMap[GA ~func() A, GB ~func() B, A, B any](fa GA, f func(A) B) GB { func MonadMap[GA ~func() A, GB ~func() B, A, B any](fa GA, f func(A) B) GB {
return MakeIO[GB](func() B { return MakeIO[GB](func() B {
return F.Pipe1(fa(), f) return f(fa())
}) })
} }
@ -66,13 +66,13 @@ func MonadMapTo[GA ~func() A, GB ~func() B, A, B any](fa GA, b B) GB {
} }
func MapTo[GA ~func() A, GB ~func() B, A, B any](b B) func(GA) GB { func MapTo[GA ~func() A, GB ~func() B, A, B any](b B) func(GA) GB {
return F.Bind2nd(MonadMapTo[GA, GB, A, B], b) return Map[GA, GB](F.Constant1[A](b))
} }
// MonadChain composes computations in sequence, using the return value of one computation to determine the next computation. // MonadChain composes computations in sequence, using the return value of one computation to determine the next computation.
func MonadChain[GA ~func() A, GB ~func() B, A, B any](fa GA, f func(A) GB) GB { func MonadChain[GA ~func() A, GB ~func() B, A, B any](fa GA, f func(A) GB) GB {
return MakeIO[GB](func() B { return MakeIO[GB](func() B {
return F.Pipe1(fa(), f)() return f(fa())()
}) })
} }
@ -88,7 +88,7 @@ func MonadChainTo[GA ~func() A, GB ~func() B, A, B any](fa GA, fb GB) GB {
// ChainTo composes computations in sequence, ignoring the return value of the first computation // ChainTo composes computations in sequence, ignoring the return value of the first computation
func ChainTo[GA ~func() A, GB ~func() B, A, B any](fb GB) func(GA) GB { func ChainTo[GA ~func() A, GB ~func() B, A, B any](fb GB) func(GA) GB {
return F.Bind2nd(MonadChainTo[GA, GB, A, B], fb) return Chain[GA, GB](F.Constant1[A](fb))
} }
// MonadChainFirst composes computations in sequence, using the return value of one computation to determine the next computation and // MonadChainFirst composes computations in sequence, using the return value of one computation to determine the next computation and
@ -174,7 +174,7 @@ func MonadFlap[FAB ~func(A) B, GFAB ~func() FAB, GB ~func() B, A, B any](fab GFA
} }
func Flap[FAB ~func(A) B, GFAB ~func() FAB, GB ~func() B, A, B any](a A) func(GFAB) GB { func Flap[FAB ~func(A) B, GFAB ~func() FAB, GB ~func() B, A, B any](a A) func(GFAB) GB {
return F.Bind2nd(MonadFlap[FAB, GFAB, GB, A, B], a) return FC.Flap(Map[GFAB, GB, FAB, B], a)
} }
// WithTime returns an operation that measures the start and end timestamp of the operation // WithTime returns an operation that measures the start and end timestamp of the operation

View File

@ -339,7 +339,7 @@ func MonadFlap[GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B]
} }
func Flap[GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], E, B, A any](a A) func(GEAB) GEB { func Flap[GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], E, B, A any](a A) func(GEAB) GEB {
return FC.Flap(MonadMap[GEAB, GEB], a) return FC.Flap(Map[GEAB, GEB], a)
} }
func ToIOOption[GA ~func() O.Option[A], GEA ~func() ET.Either[E, A], E, A any](ioe GEA) GA { func ToIOOption[GA ~func() O.Option[A], GEA ~func() ET.Either[E, A], E, A any](ioe GEA) GA {

View File

@ -159,7 +159,10 @@ func MonadAp[GB ~func() O.Option[B], GAB ~func() O.Option[func(A) B], GA ~func()
} }
func Ap[GB ~func() O.Option[B], GAB ~func() O.Option[func(A) B], GA ~func() O.Option[A], A, B any](ma GA) func(GAB) GB { func Ap[GB ~func() O.Option[B], GAB ~func() O.Option[func(A) B], GA ~func() O.Option[A], A, B any](ma GA) func(GAB) GB {
return F.Bind2nd(MonadAp[GB, GAB, GA, A, B], ma) return optiont.Ap(
IO.Ap[GB, func() func(O.Option[A]) O.Option[B], GA, O.Option[B], O.Option[A]],
IO.Map[GAB, func() func(O.Option[A]) O.Option[B], O.Option[func(A) B], func(O.Option[A]) O.Option[B]],
ma)
} }
func Flatten[GA ~func() O.Option[A], GAA ~func() O.Option[GA], A any](mma GAA) GA { func Flatten[GA ~func() O.Option[A], GAA ~func() O.Option[GA], A any](mma GAA) GA {

View File

@ -156,5 +156,5 @@ func MonadFlap[B, A any](fab Option[func(A) B], a A) Option[B] {
} }
func Flap[B, A any](a A) func(Option[func(A) B]) Option[B] { func Flap[B, A any](a A) func(Option[func(A) B]) Option[B] {
return F.Bind2nd(MonadFlap[B, A], a) return FC.Flap(Map[func(A) B, B], a)
} }

View File

@ -127,5 +127,5 @@ func MonadFlap[GAB ~func(R) func(A) B, GB ~func(R) B, R, A, B any](fab GAB, a A)
} }
func Flap[GAB ~func(R) func(A) B, GB ~func(R) B, R, A, B any](a A) func(GAB) GB { func Flap[GAB ~func(R) func(A) B, GB ~func(R) B, R, A, B any](a A) func(GAB) GB {
return FC.Flap(MonadMap[GAB, GB], a) return FC.Flap(Map[GAB, GB], a)
} }

View File

@ -162,7 +162,7 @@ func MonadFlap[GEFAB ~func(E) ET.Either[L, func(A) B], GEB ~func(E) ET.Either[L,
} }
func Flap[GEFAB ~func(E) ET.Either[L, func(A) B], GEB ~func(E) ET.Either[L, B], L, E, A, B any](a A) func(GEFAB) GEB { func Flap[GEFAB ~func(E) ET.Either[L, func(A) B], GEB ~func(E) ET.Either[L, B], L, E, A, B any](a A) func(GEFAB) GEB {
return FC.Flap(MonadMap[GEFAB, GEB], a) return FC.Flap(Map[GEFAB, GEB], a)
} }
func MonadMapLeft[GA1 ~func(C) ET.Either[E1, A], GA2 ~func(C) ET.Either[E2, A], C, E1, E2, A any](fa GA1, f func(E1) E2) GA2 { func MonadMapLeft[GA1 ~func(C) ET.Either[E1, A], GA2 ~func(C) ET.Either[E2, A], C, E1, E2, A any](fa GA1, f func(E1) E2) GA2 {

View File

@ -162,5 +162,5 @@ func MonadFlap[GEFAB ~func(E) GIOFAB, GEB ~func(E) GIOB, GIOFAB ~func() func(A)
} }
func Flap[GEFAB ~func(E) GIOFAB, GEB ~func(E) GIOB, GIOFAB ~func() func(A) B, GIOB ~func() B, E, A, B any](a A) func(GEFAB) GEB { func Flap[GEFAB ~func(E) GIOFAB, GEB ~func(E) GIOB, GIOFAB ~func() func(A) B, GIOB ~func() B, E, A, B any](a A) func(GEFAB) GEB {
return FC.Flap(MonadMap[GEFAB, GEB], a) return FC.Flap(Map[GEFAB, GEB], a)
} }

View File

@ -438,7 +438,7 @@ func MonadFlap[GREAB ~func(R) GEAB, GREB ~func(R) GEB, GEAB ~func() ET.Either[E,
} }
func Flap[GREAB ~func(R) GEAB, GREB ~func(R) GEB, GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], R, E, B, A any](a A) func(GREAB) GREB { func Flap[GREAB ~func(R) GEAB, GREB ~func(R) GEB, GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], R, E, B, A any](a A) func(GREAB) GREB {
return FC.Flap(MonadMap[GREAB, GREB], a) return FC.Flap(Map[GREAB, GREB], a)
} }
func MonadMapLeft[GREA1 ~func(R) GEA1, GREA2 ~func(R) GEA2, GEA1 ~func() ET.Either[E1, A], GEA2 ~func() ET.Either[E2, A], R, E1, E2, A any](fa GREA1, f func(E1) E2) GREA2 { func MonadMapLeft[GREA1 ~func(R) GEA1, GREA2 ~func(R) GEA2, GEA1 ~func() ET.Either[E1, A], GEA2 ~func() ET.Either[E2, A], R, E1, E2, A any](fa GREA1, f func(E1) E2) GREA2 {

View File

@ -598,7 +598,7 @@ func MonadFlap[GFAB ~map[K]func(A) B, GB ~map[K]B, K comparable, A, B any](fab G
} }
func Flap[GFAB ~map[K]func(A) B, GB ~map[K]B, K comparable, A, B any](a A) func(GFAB) GB { func Flap[GFAB ~map[K]func(A) B, GB ~map[K]B, K comparable, A, B any](a A) func(GFAB) GB {
return FC.Flap(MonadMap[GFAB, GB], a) return FC.Flap(Map[GFAB, GB], a)
} }
func Copy[M ~map[K]V, K comparable, V any](m M) M { func Copy[M ~map[K]V, K comparable, V any](m M) M {