1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-11-27 22:28:29 +02:00

fix: unwrap deep nesting of applicatives

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-13 22:38:51 +02:00
parent 177979354c
commit e42d399509
7 changed files with 76 additions and 25 deletions

View File

@@ -86,23 +86,19 @@ func generateSequenceT(f *os.File, i int) {
} }
fmt.Fprintf(f, ") HKT_TUPLE%d {\n", i) fmt.Fprintf(f, ") HKT_TUPLE%d {\n", i)
fmt.Fprintf(f, " return ") fmt.Fprintf(f, " r1 := fmap(t1, tupleConstructor%d[", i)
for j := i - 1; j >= 1; j-- {
fmt.Fprintf(f, "fap%d(", j)
}
fmt.Fprintf(f, "fmap(t1, tupleConstructor%d[", i)
for j := 0; j < i; j++ { for j := 0; j < i; j++ {
if j > 0 { if j > 0 {
fmt.Fprintf(f, ", ") fmt.Fprintf(f, ", ")
} }
fmt.Fprintf(f, "T%d", j+1) fmt.Fprintf(f, "T%d", j+1)
} }
fmt.Fprintf(f, "]())") fmt.Fprintf(f, "]())\n")
for j := 1; j < i; j++ { for j := 1; j < i; j++ {
fmt.Fprintf(f, ", t%d)", j+1) fmt.Fprintf(f, " r%d := fap%d(r%d, t%d)\n", j+1, j, j, j+1)
} }
fmt.Fprintf(f, "\n") fmt.Fprintf(f, " return r%d\n", i)
fmt.Fprintf(f, "}\n") fmt.Fprintf(f, "}\n")
} }

View File

@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 22:20:17.8012235 +0200 CEST m=+0.012514201 // 2023-07-13 22:33:52.2075869 +0200 CEST m=+0.011616301
package either package either

View File

@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 22:20:22.6778 +0200 CEST m=+0.027037401 // 2023-07-13 22:33:56.702075 +0200 CEST m=+0.040313201
package function package function
// Combinations for a total of 1 arguments // Combinations for a total of 1 arguments

View File

@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 22:20:19.9258272 +0200 CEST m=+0.046352501 // 2023-07-13 22:33:54.31999 +0200 CEST m=+0.046543601
package function package function
// Pipe0 takes an initial value t0 and successively applies 0 functions where the input of a function is the return value of the previous function // Pipe0 takes an initial value t0 and successively applies 0 functions where the input of a function is the return value of the previous function

View File

@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 22:20:24.7376009 +0200 CEST m=+0.056113801 // 2023-07-13 22:33:59.3945287 +0200 CEST m=+0.045093901
package apply package apply
@@ -25,7 +25,8 @@ func SequenceT1[
fmap MAP, fmap MAP,
t1 HKT_T1, t1 HKT_T1,
) HKT_TUPLE1 { ) HKT_TUPLE1 {
return fmap(t1, tupleConstructor1[T1]()) r1 := fmap(t1, tupleConstructor1[T1]())
return r1
} }
// tupleConstructor2 returns a curried version of [T.MakeTuple2] // tupleConstructor2 returns a curried version of [T.MakeTuple2]
@@ -50,7 +51,9 @@ func SequenceT2[
t1 HKT_T1, t1 HKT_T1,
t2 HKT_T2, t2 HKT_T2,
) HKT_TUPLE2 { ) HKT_TUPLE2 {
return fap1(fmap(t1, tupleConstructor2[T1, T2]()), t2) r1 := fmap(t1, tupleConstructor2[T1, T2]())
r2 := fap1(r1, t2)
return r2
} }
// tupleConstructor3 returns a curried version of [T.MakeTuple3] // tupleConstructor3 returns a curried version of [T.MakeTuple3]
@@ -81,7 +84,10 @@ func SequenceT3[
t2 HKT_T2, t2 HKT_T2,
t3 HKT_T3, t3 HKT_T3,
) HKT_TUPLE3 { ) HKT_TUPLE3 {
return fap2(fap1(fmap(t1, tupleConstructor3[T1, T2, T3]()), t2), t3) r1 := fmap(t1, tupleConstructor3[T1, T2, T3]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
return r3
} }
// tupleConstructor4 returns a curried version of [T.MakeTuple4] // tupleConstructor4 returns a curried version of [T.MakeTuple4]
@@ -118,7 +124,11 @@ func SequenceT4[
t3 HKT_T3, t3 HKT_T3,
t4 HKT_T4, t4 HKT_T4,
) HKT_TUPLE4 { ) HKT_TUPLE4 {
return fap3(fap2(fap1(fmap(t1, tupleConstructor4[T1, T2, T3, T4]()), t2), t3), t4) r1 := fmap(t1, tupleConstructor4[T1, T2, T3, T4]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
r4 := fap3(r3, t4)
return r4
} }
// tupleConstructor5 returns a curried version of [T.MakeTuple5] // tupleConstructor5 returns a curried version of [T.MakeTuple5]
@@ -161,7 +171,12 @@ func SequenceT5[
t4 HKT_T4, t4 HKT_T4,
t5 HKT_T5, t5 HKT_T5,
) HKT_TUPLE5 { ) HKT_TUPLE5 {
return fap4(fap3(fap2(fap1(fmap(t1, tupleConstructor5[T1, T2, T3, T4, T5]()), t2), t3), t4), t5) r1 := fmap(t1, tupleConstructor5[T1, T2, T3, T4, T5]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
r4 := fap3(r3, t4)
r5 := fap4(r4, t5)
return r5
} }
// tupleConstructor6 returns a curried version of [T.MakeTuple6] // tupleConstructor6 returns a curried version of [T.MakeTuple6]
@@ -210,7 +225,13 @@ func SequenceT6[
t5 HKT_T5, t5 HKT_T5,
t6 HKT_T6, t6 HKT_T6,
) HKT_TUPLE6 { ) HKT_TUPLE6 {
return fap5(fap4(fap3(fap2(fap1(fmap(t1, tupleConstructor6[T1, T2, T3, T4, T5, T6]()), t2), t3), t4), t5), t6) r1 := fmap(t1, tupleConstructor6[T1, T2, T3, T4, T5, T6]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
r4 := fap3(r3, t4)
r5 := fap4(r4, t5)
r6 := fap5(r5, t6)
return r6
} }
// tupleConstructor7 returns a curried version of [T.MakeTuple7] // tupleConstructor7 returns a curried version of [T.MakeTuple7]
@@ -265,7 +286,14 @@ func SequenceT7[
t6 HKT_T6, t6 HKT_T6,
t7 HKT_T7, t7 HKT_T7,
) HKT_TUPLE7 { ) HKT_TUPLE7 {
return fap6(fap5(fap4(fap3(fap2(fap1(fmap(t1, tupleConstructor7[T1, T2, T3, T4, T5, T6, T7]()), t2), t3), t4), t5), t6), t7) r1 := fmap(t1, tupleConstructor7[T1, T2, T3, T4, T5, T6, T7]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
r4 := fap3(r3, t4)
r5 := fap4(r4, t5)
r6 := fap5(r5, t6)
r7 := fap6(r6, t7)
return r7
} }
// tupleConstructor8 returns a curried version of [T.MakeTuple8] // tupleConstructor8 returns a curried version of [T.MakeTuple8]
@@ -326,7 +354,15 @@ func SequenceT8[
t7 HKT_T7, t7 HKT_T7,
t8 HKT_T8, t8 HKT_T8,
) HKT_TUPLE8 { ) HKT_TUPLE8 {
return fap7(fap6(fap5(fap4(fap3(fap2(fap1(fmap(t1, tupleConstructor8[T1, T2, T3, T4, T5, T6, T7, T8]()), t2), t3), t4), t5), t6), t7), t8) r1 := fmap(t1, tupleConstructor8[T1, T2, T3, T4, T5, T6, T7, T8]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
r4 := fap3(r3, t4)
r5 := fap4(r4, t5)
r6 := fap5(r5, t6)
r7 := fap6(r6, t7)
r8 := fap7(r7, t8)
return r8
} }
// tupleConstructor9 returns a curried version of [T.MakeTuple9] // tupleConstructor9 returns a curried version of [T.MakeTuple9]
@@ -393,7 +429,16 @@ func SequenceT9[
t8 HKT_T8, t8 HKT_T8,
t9 HKT_T9, t9 HKT_T9,
) HKT_TUPLE9 { ) HKT_TUPLE9 {
return fap8(fap7(fap6(fap5(fap4(fap3(fap2(fap1(fmap(t1, tupleConstructor9[T1, T2, T3, T4, T5, T6, T7, T8, T9]()), t2), t3), t4), t5), t6), t7), t8), t9) r1 := fmap(t1, tupleConstructor9[T1, T2, T3, T4, T5, T6, T7, T8, T9]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
r4 := fap3(r3, t4)
r5 := fap4(r4, t5)
r6 := fap5(r5, t6)
r7 := fap6(r6, t7)
r8 := fap7(r7, t8)
r9 := fap8(r8, t9)
return r9
} }
// tupleConstructor10 returns a curried version of [T.MakeTuple10] // tupleConstructor10 returns a curried version of [T.MakeTuple10]
@@ -466,5 +511,15 @@ func SequenceT10[
t9 HKT_T9, t9 HKT_T9,
t10 HKT_T10, t10 HKT_T10,
) HKT_TUPLE10 { ) HKT_TUPLE10 {
return fap9(fap8(fap7(fap6(fap5(fap4(fap3(fap2(fap1(fmap(t1, tupleConstructor10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]()), t2), t3), t4), t5), t6), t7), t8), t9), t10) r1 := fmap(t1, tupleConstructor10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]())
r2 := fap1(r1, t2)
r3 := fap2(r2, t3)
r4 := fap3(r3, t4)
r5 := fap4(r4, t5)
r6 := fap5(r5, t6)
r7 := fap6(r6, t7)
r8 := fap7(r7, t8)
r9 := fap8(r8, t9)
r10 := fap9(r9, t10)
return r10
} }

View File

@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 22:20:27.1434383 +0200 CEST m=+0.033978401 // 2023-07-13 22:34:01.4247214 +0200 CEST m=+0.038058501
package option package option
// optionize converts a nullary function to an option // optionize converts a nullary function to an option

View File

@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 22:20:30.1912026 +0200 CEST m=+0.048006501 // 2023-07-13 22:34:03.5413159 +0200 CEST m=+0.012707901
package tuple package tuple