1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-10 22:31:32 +02:00

fix: add automation for TraverseTuple and SequenceTuple

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-17 13:55:35 +02:00
parent 48f38f2e43
commit 69c2fe1118
16 changed files with 4820 additions and 2483 deletions

View File

@@ -10,10 +10,10 @@ import (
C "github.com/urfave/cli/v2" C "github.com/urfave/cli/v2"
) )
func generateSequenceT(f *os.File, i int) { func generateTraverseTuple(f *os.File, i int) {
fmt.Fprintf(f, "\n// SequenceT%d is a utility function used to implement the sequence operation for higher kinded types based only on map and ap.\n", i) fmt.Fprintf(f, "\n// TraverseTuple%d is a utility function used to implement the sequence operation for higher kinded types based only on map and ap.\n", i)
fmt.Fprintf(f, "// The function takes %d higher higher kinded types and returns a higher kinded type of a [Tuple%d] with the resolved values.\n", i, i) fmt.Fprintf(f, "// The function takes a [Tuple%d] of base types and %d functions that transform these based types into higher higher kinded types. It returns a higher kinded type of a [Tuple%d] with the resolved values.\n", i, i, i)
fmt.Fprintf(f, "func SequenceT%d[\n", i) fmt.Fprintf(f, "func TraverseTuple%d[\n", i)
// map as the starting point // map as the starting point
fmt.Fprintf(f, " MAP ~func(") fmt.Fprintf(f, " MAP ~func(")
for j := 0; j < i; j++ { for j := 0; j < i; j++ {
@@ -24,7 +24,115 @@ func generateSequenceT(f *os.File, i int) {
} }
fmt.Fprintf(f, " ") fmt.Fprintf(f, " ")
fmt.Fprintf(f, "T.") fmt.Fprintf(f, "T.")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, ") func(HKT_T1)")
if i > 1 {
fmt.Fprintf(f, " HKT_F")
for k := 1; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
} else {
fmt.Fprintf(f, " HKT_TUPLE%d", i)
}
fmt.Fprintf(f, ",\n")
// the applicatives
for j := 1; j < i; j++ {
fmt.Fprintf(f, " AP%d ~func(", j)
fmt.Fprintf(f, "HKT_T%d) func(", j+1)
fmt.Fprintf(f, "HKT_F")
for k := j; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
fmt.Fprintf(f, ")")
if j+1 < i {
fmt.Fprintf(f, " HKT_F")
for k := j + 1; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
} else {
fmt.Fprintf(f, " HKT_TUPLE%d", i)
}
fmt.Fprintf(f, ",\n")
}
for j := 0; j < i; j++ {
fmt.Fprintf(f, " F%d ~func(A%d) HKT_T%d,\n", j+1, j+1, j+1)
}
for j := 0; j < i; j++ {
fmt.Fprintf(f, " A%d, T%d,\n", j+1, j+1)
}
for j := 0; j < i; j++ {
fmt.Fprintf(f, " HKT_T%d, // HKT[T%d]\n", j+1, j+1)
}
for j := 1; j < i; j++ {
fmt.Fprintf(f, " HKT_F")
for k := j; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
fmt.Fprintf(f, ", // HKT[")
for k := j; k < i; k++ {
fmt.Fprintf(f, "func(T%d) ", k+1)
}
fmt.Fprintf(f, "T.")
writeTupleType(f, "T", i)
fmt.Fprintf(f, "]\n")
}
fmt.Fprintf(f, " HKT_TUPLE%d any, // HKT[", i)
writeTupleType(f, "T", i)
fmt.Fprintf(f, "]\n")
fmt.Fprintf(f, "](\n")
// the callbacks
fmt.Fprintf(f, " fmap MAP,\n")
for j := 1; j < i; j++ {
fmt.Fprintf(f, " fap%d AP%d,\n", j, j)
}
// the transformer functions
for j := 1; j <= i; j++ {
fmt.Fprintf(f, " f%d F%d,\n", j, j)
}
// the parameters
fmt.Fprintf(f, " t T.Tuple%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "A%d", j+1)
}
fmt.Fprintf(f, "],\n")
fmt.Fprintf(f, ") HKT_TUPLE%d {\n", i)
fmt.Fprintf(f, " return F.Pipe%d(\n", i)
fmt.Fprintf(f, " f1(t.F1),\n")
fmt.Fprintf(f, " fmap(tupleConstructor%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, "]()),\n")
for j := 1; j < i; j++ {
fmt.Fprintf(f, " fap%d(f%d(t.F%d)),\n", j, j+1, j+1)
}
fmt.Fprintf(f, ")\n")
fmt.Fprintf(f, "}\n")
}
func generateSequenceTuple(f *os.File, i int) {
fmt.Fprintf(f, "\n// SequenceTuple%d is a utility function used to implement the sequence operation for higher kinded types based only on map and ap.\n", i)
fmt.Fprintf(f, "// The function takes a [Tuple%d] of higher higher kinded types and returns a higher kinded type of a [Tuple%d] with the resolved values.\n", i, i)
fmt.Fprintf(f, "func SequenceTuple%d[\n", i)
// map as the starting point
fmt.Fprintf(f, " MAP ~func(")
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "func(T%d)", j+1)
}
fmt.Fprintf(f, " ")
fmt.Fprintf(f, "T.")
writeTupleType(f, "T", i)
fmt.Fprintf(f, ") func(HKT_T1)") fmt.Fprintf(f, ") func(HKT_T1)")
if i > 1 { if i > 1 {
fmt.Fprintf(f, " HKT_F") fmt.Fprintf(f, " HKT_F")
@@ -71,11 +179,113 @@ func generateSequenceT(f *os.File, i int) {
fmt.Fprintf(f, "func(T%d) ", k+1) fmt.Fprintf(f, "func(T%d) ", k+1)
} }
fmt.Fprintf(f, "T.") fmt.Fprintf(f, "T.")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, "]\n") fmt.Fprintf(f, "]\n")
} }
fmt.Fprintf(f, " HKT_TUPLE%d any, // HKT[", i) fmt.Fprintf(f, " HKT_TUPLE%d any, // HKT[", i)
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, "]\n")
fmt.Fprintf(f, "](\n")
// the callbacks
fmt.Fprintf(f, " fmap MAP,\n")
for j := 1; j < i; j++ {
fmt.Fprintf(f, " fap%d AP%d,\n", j, j)
}
// the parameters
fmt.Fprintf(f, " t T.Tuple%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "HKT_T%d", j+1)
}
fmt.Fprintf(f, "],\n")
fmt.Fprintf(f, ") HKT_TUPLE%d {\n", i)
fmt.Fprintf(f, " return F.Pipe%d(\n", i)
fmt.Fprintf(f, " t.F1,\n")
fmt.Fprintf(f, " fmap(tupleConstructor%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, "]()),\n")
for j := 1; j < i; j++ {
fmt.Fprintf(f, " fap%d(t.F%d),\n", j, j+1)
}
fmt.Fprintf(f, ")\n")
fmt.Fprintf(f, "}\n")
}
func generateSequenceT(f *os.File, i int) {
fmt.Fprintf(f, "\n// SequenceT%d is a utility function used to implement the sequence operation for higher kinded types based only on map and ap.\n", i)
fmt.Fprintf(f, "// The function takes %d higher higher kinded types and returns a higher kinded type of a [Tuple%d] with the resolved values.\n", i, i)
fmt.Fprintf(f, "func SequenceT%d[\n", i)
// map as the starting point
fmt.Fprintf(f, " MAP ~func(")
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "func(T%d)", j+1)
}
fmt.Fprintf(f, " ")
fmt.Fprintf(f, "T.")
writeTupleType(f, "T", i)
fmt.Fprintf(f, ") func(HKT_T1)")
if i > 1 {
fmt.Fprintf(f, " HKT_F")
for k := 1; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
} else {
fmt.Fprintf(f, " HKT_TUPLE%d", i)
}
fmt.Fprintf(f, ",\n")
// the applicatives
for j := 1; j < i; j++ {
fmt.Fprintf(f, " AP%d ~func(", j)
fmt.Fprintf(f, "HKT_T%d) func(", j+1)
fmt.Fprintf(f, "HKT_F")
for k := j; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
fmt.Fprintf(f, ")")
if j+1 < i {
fmt.Fprintf(f, " HKT_F")
for k := j + 1; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
} else {
fmt.Fprintf(f, " HKT_TUPLE%d", i)
}
fmt.Fprintf(f, ",\n")
}
for j := 0; j < i; j++ {
fmt.Fprintf(f, " T%d,\n", j+1)
}
for j := 0; j < i; j++ {
fmt.Fprintf(f, " HKT_T%d, // HKT[T%d]\n", j+1, j+1)
}
for j := 1; j < i; j++ {
fmt.Fprintf(f, " HKT_F")
for k := j; k < i; k++ {
fmt.Fprintf(f, "_T%d", k+1)
}
fmt.Fprintf(f, ", // HKT[")
for k := j; k < i; k++ {
fmt.Fprintf(f, "func(T%d) ", k+1)
}
fmt.Fprintf(f, "T.")
writeTupleType(f, "T", i)
fmt.Fprintf(f, "]\n")
}
fmt.Fprintf(f, " HKT_TUPLE%d any, // HKT[", i)
writeTupleType(f, "T", i)
fmt.Fprintf(f, "]\n") fmt.Fprintf(f, "]\n")
fmt.Fprintf(f, "](\n") fmt.Fprintf(f, "](\n")
@@ -180,6 +390,10 @@ import (
generateTupleConstructor(f, i) generateTupleConstructor(f, i)
// sequenceT // sequenceT
generateSequenceT(f, i) generateSequenceT(f, i)
// sequenceTuple
generateSequenceTuple(f, i)
// traverseTuple
generateTraverseTuple(f, i)
} }
return nil return nil

View File

@@ -10,6 +10,65 @@ import (
C "github.com/urfave/cli/v2" C "github.com/urfave/cli/v2"
) )
func eitherHKT(typeE string) func(typeA string) string {
return func(typeA string) string {
return fmt.Sprintf("Either[%s, %s]", typeE, typeA)
}
}
func generateEitherTraverseTuple(f *os.File, i int) {
generateTraverseTuple1(eitherHKT("E"), "E")(f, i)
}
func generateEitherSequenceTuple(f *os.File, i int) {
generateSequenceTuple1(eitherHKT("E"), "E")(f, i)
}
func generateEitherSequenceT(f *os.File, i int) {
tuple := tupleType(i)
fmt.Fprintf(f, "\n// SequenceT%d converts %d parameters of [Either[E, T]] into an [Either] of a [Tuple%d].\n", i, i, i)
fmt.Fprintf(f, "func SequenceT%d[E", i)
for j := 0; j < i; j++ {
fmt.Fprintf(f, ", T%d", j+1)
}
fmt.Fprintf(f, " any](")
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "t%d Either[E, T%d]", j+1, j+1)
}
fmt.Fprintf(f, ") Either[E, %s] {\n", tuple)
fmt.Fprintf(f, " return A.SequenceT%d(\n", i)
// map
fmt.Fprintf(f, " Map[E, T1,")
for j := 1; j < i; j++ {
fmt.Fprintf(f, " func(T%d)", j+1)
}
fmt.Fprintf(f, " %s],\n", tuple)
// applicatives
for j := 1; j < i; j++ {
fmt.Fprintf(f, " Ap[")
for k := j + 1; k < i; k++ {
if k > j+1 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "func(T%d)", k+1)
}
if j < i-1 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "%s, E, T%d],\n", tuple, j+1)
}
for j := 0; j < i; j++ {
fmt.Fprintf(f, " t%d,\n", j+1)
}
fmt.Fprintf(f, " )\n")
fmt.Fprintf(f, "}\n")
}
func generateUneitherize(f *os.File, i int) { func generateUneitherize(f *os.File, i int) {
// Create the optionize version // Create the optionize version
fmt.Fprintf(f, "\n// Uneitherize%d converts a function with %d parameters returning an Either into a function with %d parameters returning a tuple\n// The inverse function is [Eitherize%d]\n", i, i, i, i) fmt.Fprintf(f, "\n// Uneitherize%d converts a function with %d parameters returning an Either into a function with %d parameters returning a tuple\n// The inverse function is [Eitherize%d]\n", i, i, i, i)
@@ -121,6 +180,13 @@ func generateEitherHelpers(filename string, count int) error {
fmt.Fprintf(f, "package %s\n\n", pkg) fmt.Fprintf(f, "package %s\n\n", pkg)
fmt.Fprintf(f, `
import (
A "github.com/ibm/fp-go/internal/apply"
T "github.com/ibm/fp-go/tuple"
)
`)
// zero level functions // zero level functions
// optionize // optionize
@@ -133,6 +199,12 @@ func generateEitherHelpers(filename string, count int) error {
generateEitherize(f, i) generateEitherize(f, i)
// unoptionize // unoptionize
generateUneitherize(f, i) generateUneitherize(f, i)
// sequenceT
generateEitherSequenceT(f, i)
// sequenceTuple
generateEitherSequenceTuple(f, i)
// traverseTuple
generateEitherTraverseTuple(f, i)
} }
return nil return nil

View File

@@ -125,3 +125,152 @@ func monadGenerateSequenceTGeneric(
} }
} }
func generateTraverseTuple1(
hkt func(string) string,
infix string) func(f *os.File, i int) {
return func(f *os.File, i int) {
tuple := tupleType(i)
fmt.Fprintf(f, "\n// TraverseTuple%d converts a [Tuple%d] of [A] via transformation functions transforming [A] to [%s] into a [%s].\n", i, i, hkt("A"), hkt(fmt.Sprintf("Tuple%d", i)))
fmt.Fprintf(f, "func TraverseTuple%d[", i)
// functions
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "F%d ~func(A%d) %s", j+1, j+1, hkt(fmt.Sprintf("T%d", j+1)))
}
if infix != "" {
fmt.Fprintf(f, ", %s", infix)
}
// types
for j := 0; j < i; j++ {
fmt.Fprintf(f, ", A%d, T%d", j+1, j+1)
}
fmt.Fprintf(f, " any](")
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "f%d F%d", j+1, j+1)
}
fmt.Fprintf(f, ") func (T.Tuple%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "A%d", j+1)
}
fmt.Fprintf(f, "]) %s {\n", hkt(tuple))
fmt.Fprintf(f, " return func(t T.Tuple%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "A%d", j+1)
}
fmt.Fprintf(f, "]) %s {\n", hkt(tuple))
fmt.Fprintf(f, " return A.TraverseTuple%d(\n", i)
// map
fmt.Fprintf(f, " Map[")
if infix != "" {
fmt.Fprintf(f, "%s, T1,", infix)
} else {
fmt.Fprintf(f, "T1,")
}
for j := 1; j < i; j++ {
fmt.Fprintf(f, " func(T%d)", j+1)
}
fmt.Fprintf(f, " %s],\n", tuple)
// applicatives
for j := 1; j < i; j++ {
fmt.Fprintf(f, " Ap[")
for k := j + 1; k < i; k++ {
if k > j+1 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "func(T%d)", k+1)
}
if j < i-1 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "%s", tuple)
if infix != "" {
fmt.Fprintf(f, ", %s", infix)
}
fmt.Fprintf(f, ", T%d],\n", j+1)
}
for j := 0; j < i; j++ {
fmt.Fprintf(f, " f%d,\n", j+1)
}
fmt.Fprintf(f, " t,\n")
fmt.Fprintf(f, " )\n")
fmt.Fprintf(f, " }\n")
fmt.Fprintf(f, "}\n")
}
}
func generateSequenceTuple1(
hkt func(string) string,
infix string) func(f *os.File, i int) {
return func(f *os.File, i int) {
tuple := tupleType(i)
fmt.Fprintf(f, "\n// SequenceTuple%d converts a [Tuple%d] of [%s] into an [%s].\n", i, i, hkt("T"), hkt(fmt.Sprintf("Tuple%d", i)))
fmt.Fprintf(f, "func SequenceTuple%d[", i)
if infix != "" {
fmt.Fprintf(f, "%s", infix)
}
for j := 0; j < i; j++ {
if infix != "" || j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, " any](t T.Tuple%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "%s", hkt(fmt.Sprintf("T%d", j+1)))
}
fmt.Fprintf(f, "]) %s {\n", hkt(tuple))
fmt.Fprintf(f, " return A.SequenceTuple%d(\n", i)
// map
fmt.Fprintf(f, " Map[")
if infix != "" {
fmt.Fprintf(f, "%s, T1,", infix)
} else {
fmt.Fprintf(f, "T1,")
}
for j := 1; j < i; j++ {
fmt.Fprintf(f, " func(T%d)", j+1)
}
fmt.Fprintf(f, " %s],\n", tuple)
// applicatives
for j := 1; j < i; j++ {
fmt.Fprintf(f, " Ap[")
for k := j + 1; k < i; k++ {
if k > j+1 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "func(T%d)", k+1)
}
if j < i-1 {
fmt.Fprintf(f, " ")
}
fmt.Fprintf(f, "%s", tuple)
if infix != "" {
fmt.Fprintf(f, ", %s", infix)
}
fmt.Fprintf(f, ", T%d],\n", j+1)
}
fmt.Fprintf(f, " t,\n")
fmt.Fprintf(f, " )\n")
fmt.Fprintf(f, "}\n")
}
}

View File

@@ -10,6 +10,18 @@ import (
C "github.com/urfave/cli/v2" C "github.com/urfave/cli/v2"
) )
func optionHKT(typeA string) string {
return fmt.Sprintf("Option[%s]", typeA)
}
func generateOptionTraverseTuple(f *os.File, i int) {
generateTraverseTuple1(optionHKT, "")(f, i)
}
func generateOptionSequenceTuple(f *os.File, i int) {
generateSequenceTuple1(optionHKT, "")(f, i)
}
func generateOptionize(f *os.File, i int) { func generateOptionize(f *os.File, i int) {
// Create the optionize version // Create the optionize version
fmt.Fprintf(f, "\n// Optionize%d converts a function with %d parameters returning a tuple of a return value R and a boolean into a function with %d parameters returning an Option[R]\n", i, i, i) fmt.Fprintf(f, "\n// Optionize%d converts a function with %d parameters returning a tuple of a return value R and a boolean into a function with %d parameters returning an Option[R]\n", i, i, i)
@@ -121,6 +133,13 @@ func generateOptionHelpers(filename string, count int) error {
fmt.Fprintf(f, "package %s\n\n", pkg) fmt.Fprintf(f, "package %s\n\n", pkg)
fmt.Fprintf(f, `
import (
A "github.com/ibm/fp-go/internal/apply"
T "github.com/ibm/fp-go/tuple"
)
`)
// print out some helpers // print out some helpers
fmt.Fprintf(f, `// optionize converts a nullary function to an option fmt.Fprintf(f, `// optionize converts a nullary function to an option
func optionize[R any](f func() (R, bool)) Option[R] { func optionize[R any](f func() (R, bool)) Option[R] {
@@ -143,6 +162,10 @@ func optionize[R any](f func() (R, bool)) Option[R] {
generateOptionize(f, i) generateOptionize(f, i)
// unoptionize // unoptionize
generateUnoptionize(f, i) generateUnoptionize(f, i)
// sequenceTuple
generateOptionSequenceTuple(f, i)
// traverseTuple
generateOptionTraverseTuple(f, i)
} }
return nil return nil

View File

@@ -10,17 +10,84 @@ import (
C "github.com/urfave/cli/v2" C "github.com/urfave/cli/v2"
) )
func writeTupleType(f *os.File, i int) { func writeTupleType(f *os.File, symbol string, i int) {
fmt.Fprintf(f, "Tuple%d[", i) fmt.Fprintf(f, "Tuple%d[", i)
for j := 1; j <= i; j++ { for j := 1; j <= i; j++ {
if j > 1 { if j > 1 {
fmt.Fprintf(f, ", ") fmt.Fprintf(f, ", ")
} }
fmt.Fprintf(f, "T%d", j) fmt.Fprintf(f, "%s%d", symbol, j)
} }
fmt.Fprintf(f, "]") fmt.Fprintf(f, "]")
} }
func generateReplicate(f *os.File, i int) {
// Create the optionize version
fmt.Fprintf(f, "\n// Replicate%d creates a [Tuple%d] with all fields set to the input value `t`\n", i, i)
fmt.Fprintf(f, "func Replicate%d[T any](t T) Tuple%d[", i, i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T")
}
fmt.Fprintf(f, "] {\n")
// execute the mapping
fmt.Fprintf(f, " return MakeTuple%d(", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "t")
}
fmt.Fprintf(f, ")\n")
fmt.Fprintf(f, "}\n")
}
func generateMap(f *os.File, i int) {
// Create the optionize version
fmt.Fprintf(f, "\n// Map%d maps each value of a [Tuple%d] via a mapping function\n", i, i)
fmt.Fprintf(f, "func Map%d[", i)
// function prototypes
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "F%d ~func(T%d) R%d", j, j, j)
}
for j := 1; j <= i; j++ {
fmt.Fprintf(f, ", T%d, R%d", j, j)
}
fmt.Fprintf(f, " any](")
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "f%d F%d", j, j)
}
fmt.Fprintf(f, ") func(")
writeTupleType(f, "T", i)
fmt.Fprintf(f, ") ")
writeTupleType(f, "R", i)
fmt.Fprintf(f, " {\n")
fmt.Fprintf(f, " return func(t ")
writeTupleType(f, "T", i)
fmt.Fprintf(f, ") ")
writeTupleType(f, "R", i)
fmt.Fprintf(f, " {\n")
// execute the mapping
fmt.Fprintf(f, " return MakeTuple%d(\n", i)
for j := 1; j <= i; j++ {
fmt.Fprintf(f, " f%d(t.F%d),\n", j, j)
}
fmt.Fprintf(f, " )\n")
fmt.Fprintf(f, " }\n")
fmt.Fprintf(f, "}\n")
}
func generateMonoid(f *os.File, i int) { func generateMonoid(f *os.File, i int) {
// Create the optionize version // Create the optionize version
fmt.Fprintf(f, "\n// Monoid%d creates a [Monoid] for a [Tuple%d] based on %d monoids for the contained types\n", i, i, i) fmt.Fprintf(f, "\n// Monoid%d creates a [Monoid] for a [Tuple%d] based on %d monoids for the contained types\n", i, i, i)
@@ -39,13 +106,13 @@ func generateMonoid(f *os.File, i int) {
fmt.Fprintf(f, "m%d M.Monoid[T%d]", j, j) fmt.Fprintf(f, "m%d M.Monoid[T%d]", j, j)
} }
fmt.Fprintf(f, ") M.Monoid[") fmt.Fprintf(f, ") M.Monoid[")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, "] {\n") fmt.Fprintf(f, "] {\n")
fmt.Fprintf(f, " return M.MakeMonoid(func(l, r ") fmt.Fprintf(f, " return M.MakeMonoid(func(l, r ")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, ") ") fmt.Fprintf(f, ") ")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, "{\n") fmt.Fprintf(f, "{\n")
fmt.Fprintf(f, " return MakeTuple%d(", i) fmt.Fprintf(f, " return MakeTuple%d(", i)
@@ -86,11 +153,11 @@ func generateOrd(f *os.File, i int) {
fmt.Fprintf(f, "o%d O.Ord[T%d]", j, j) fmt.Fprintf(f, "o%d O.Ord[T%d]", j, j)
} }
fmt.Fprintf(f, ") O.Ord[") fmt.Fprintf(f, ") O.Ord[")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, "] {\n") fmt.Fprintf(f, "] {\n")
fmt.Fprintf(f, " return O.MakeOrd(func(l, r ") fmt.Fprintf(f, " return O.MakeOrd(func(l, r ")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, ") int {\n") fmt.Fprintf(f, ") int {\n")
for j := 1; j <= i; j++ { for j := 1; j <= i; j++ {
@@ -98,7 +165,7 @@ func generateOrd(f *os.File, i int) {
} }
fmt.Fprintf(f, " return 0\n") fmt.Fprintf(f, " return 0\n")
fmt.Fprintf(f, " }, func(l, r ") fmt.Fprintf(f, " }, func(l, r ")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, ") bool {\n") fmt.Fprintf(f, ") bool {\n")
fmt.Fprintf(f, " return ") fmt.Fprintf(f, " return ")
for j := 1; j <= i; j++ { for j := 1; j <= i; j++ {
@@ -148,7 +215,7 @@ func generateMakeTupleType(f *os.File, i int) {
fmt.Fprintf(f, "t%d T%d", j, j) fmt.Fprintf(f, "t%d T%d", j, j)
} }
fmt.Fprintf(f, ") ") fmt.Fprintf(f, ") ")
writeTupleType(f, i) writeTupleType(f, "T", i)
fmt.Fprintf(f, " {\n") fmt.Fprintf(f, " {\n")
fmt.Fprintf(f, " return Tuple%d[", i) fmt.Fprintf(f, " return Tuple%d[", i)
for j := 1; j <= i; j++ { for j := 1; j <= i; j++ {
@@ -300,6 +367,10 @@ import (
generateMonoid(f, i) generateMonoid(f, i)
// generate order // generate order
generateOrd(f, i) generateOrd(f, i)
// generate map
generateMap(f, i)
// generate replicate
generateReplicate(f, i)
} }
return nil return nil

View File

@@ -1,3 +1,3 @@
package either package either
//go:generate go run .. either --count 10 --filename eitherize.go //go:generate go run .. either --count 10 --filename gen.go

View File

@@ -1,202 +0,0 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2023-07-14 13:19:40.5850892 +0200 CEST m=+0.008180901
package either
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning an Either
// The inverse function is [Uneitherize0]
func Eitherize0[F ~func() (R, error), R any](f F) func() Either[error, R] {
return func() Either[error, R] {
return TryCatchError(func() (R, error) {
return f()
})
}
}
// Uneitherize0 converts a function with 0 parameters returning an Either into a function with 0 parameters returning a tuple
// The inverse function is [Eitherize0]
func Uneitherize0[F ~func() Either[error, R], R any](f F) func() (R, error) {
return func() (R, error) {
return UnwrapError(f())
}
}
// Eitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning an Either
// The inverse function is [Uneitherize1]
func Eitherize1[F ~func(T0) (R, error), T0, R any](f F) func(T0) Either[error, R] {
return func(t0 T0) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0)
})
}
}
// Uneitherize1 converts a function with 1 parameters returning an Either into a function with 1 parameters returning a tuple
// The inverse function is [Eitherize1]
func Uneitherize1[F ~func(T0) Either[error, R], T0, R any](f F) func(T0) (R, error) {
return func(t0 T0) (R, error) {
return UnwrapError(f(t0))
}
}
// Eitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning an Either
// The inverse function is [Uneitherize2]
func Eitherize2[F ~func(T0, T1) (R, error), T0, T1, R any](f F) func(T0, T1) Either[error, R] {
return func(t0 T0, t1 T1) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1)
})
}
}
// Uneitherize2 converts a function with 2 parameters returning an Either into a function with 2 parameters returning a tuple
// The inverse function is [Eitherize2]
func Uneitherize2[F ~func(T0, T1) Either[error, R], T0, T1, R any](f F) func(T0, T1) (R, error) {
return func(t0 T0, t1 T1) (R, error) {
return UnwrapError(f(t0, t1))
}
}
// Eitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning an Either
// The inverse function is [Uneitherize3]
func Eitherize3[F ~func(T0, T1, T2) (R, error), T0, T1, T2, R any](f F) func(T0, T1, T2) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2)
})
}
}
// Uneitherize3 converts a function with 3 parameters returning an Either into a function with 3 parameters returning a tuple
// The inverse function is [Eitherize3]
func Uneitherize3[F ~func(T0, T1, T2) Either[error, R], T0, T1, T2, R any](f F) func(T0, T1, T2) (R, error) {
return func(t0 T0, t1 T1, t2 T2) (R, error) {
return UnwrapError(f(t0, t1, t2))
}
}
// Eitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning an Either
// The inverse function is [Uneitherize4]
func Eitherize4[F ~func(T0, T1, T2, T3) (R, error), T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3)
})
}
}
// Uneitherize4 converts a function with 4 parameters returning an Either into a function with 4 parameters returning a tuple
// The inverse function is [Eitherize4]
func Uneitherize4[F ~func(T0, T1, T2, T3) Either[error, R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3) (R, error) {
return UnwrapError(f(t0, t1, t2, t3))
}
}
// Eitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning an Either
// The inverse function is [Uneitherize5]
func Eitherize5[F ~func(T0, T1, T2, T3, T4) (R, error), T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4)
})
}
}
// Uneitherize5 converts a function with 5 parameters returning an Either into a function with 5 parameters returning a tuple
// The inverse function is [Eitherize5]
func Uneitherize5[F ~func(T0, T1, T2, T3, T4) Either[error, R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4))
}
}
// Eitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning an Either
// The inverse function is [Uneitherize6]
func Eitherize6[F ~func(T0, T1, T2, T3, T4, T5) (R, error), T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5)
})
}
}
// Uneitherize6 converts a function with 6 parameters returning an Either into a function with 6 parameters returning a tuple
// The inverse function is [Eitherize6]
func Uneitherize6[F ~func(T0, T1, T2, T3, T4, T5) Either[error, R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5))
}
}
// Eitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning an Either
// The inverse function is [Uneitherize7]
func Eitherize7[F ~func(T0, T1, T2, T3, T4, T5, T6) (R, error), T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6)
})
}
}
// Uneitherize7 converts a function with 7 parameters returning an Either into a function with 7 parameters returning a tuple
// The inverse function is [Eitherize7]
func Uneitherize7[F ~func(T0, T1, T2, T3, T4, T5, T6) Either[error, R], T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6))
}
}
// Eitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning an Either
// The inverse function is [Uneitherize8]
func Eitherize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7)
})
}
}
// Uneitherize8 converts a function with 8 parameters returning an Either into a function with 8 parameters returning a tuple
// The inverse function is [Eitherize8]
func Uneitherize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6, t7))
}
}
// Eitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning an Either
// The inverse function is [Uneitherize9]
func Eitherize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8)
})
}
}
// Uneitherize9 converts a function with 9 parameters returning an Either into a function with 9 parameters returning a tuple
// The inverse function is [Eitherize9]
func Uneitherize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6, t7, t8))
}
}
// Eitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning an Either
// The inverse function is [Uneitherize10]
func Eitherize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
})
}
}
// Uneitherize10 converts a function with 10 parameters returning an Either into a function with 10 parameters returning a tuple
// The inverse function is [Eitherize10]
func Uneitherize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
}
}

703
either/gen.go Normal file
View File

@@ -0,0 +1,703 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2023-07-17 13:22:56.8771166 +0200 CEST m=+0.010453601
package either
import (
A "github.com/ibm/fp-go/internal/apply"
T "github.com/ibm/fp-go/tuple"
)
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning an Either
// The inverse function is [Uneitherize0]
func Eitherize0[F ~func() (R, error), R any](f F) func() Either[error, R] {
return func() Either[error, R] {
return TryCatchError(func() (R, error) {
return f()
})
}
}
// Uneitherize0 converts a function with 0 parameters returning an Either into a function with 0 parameters returning a tuple
// The inverse function is [Eitherize0]
func Uneitherize0[F ~func() Either[error, R], R any](f F) func() (R, error) {
return func() (R, error) {
return UnwrapError(f())
}
}
// Eitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning an Either
// The inverse function is [Uneitherize1]
func Eitherize1[F ~func(T0) (R, error), T0, R any](f F) func(T0) Either[error, R] {
return func(t0 T0) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0)
})
}
}
// Uneitherize1 converts a function with 1 parameters returning an Either into a function with 1 parameters returning a tuple
// The inverse function is [Eitherize1]
func Uneitherize1[F ~func(T0) Either[error, R], T0, R any](f F) func(T0) (R, error) {
return func(t0 T0) (R, error) {
return UnwrapError(f(t0))
}
}
// SequenceT1 converts 1 parameters of [Either[E, T]] into an [Either] of a [Tuple1].
func SequenceT1[E, T1 any](t1 Either[E, T1]) Either[E, T.Tuple1[T1]] {
return A.SequenceT1(
Map[E, T1, T.Tuple1[T1]],
t1,
)
}
// SequenceTuple1 converts a [Tuple1] of [Either[E, T]] into an [Either[E, Tuple1]].
func SequenceTuple1[E, T1 any](t T.Tuple1[Either[E, T1]]) Either[E, T.Tuple1[T1]] {
return A.SequenceTuple1(
Map[E, T1, T.Tuple1[T1]],
t,
)
}
// TraverseTuple1 converts a [Tuple1] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple1]].
func TraverseTuple1[F1 ~func(A1) Either[E, T1], E, A1, T1 any](f1 F1) func (T.Tuple1[A1]) Either[E, T.Tuple1[T1]] {
return func(t T.Tuple1[A1]) Either[E, T.Tuple1[T1]] {
return A.TraverseTuple1(
Map[E, T1, T.Tuple1[T1]],
f1,
t,
)
}
}
// Eitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning an Either
// The inverse function is [Uneitherize2]
func Eitherize2[F ~func(T0, T1) (R, error), T0, T1, R any](f F) func(T0, T1) Either[error, R] {
return func(t0 T0, t1 T1) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1)
})
}
}
// Uneitherize2 converts a function with 2 parameters returning an Either into a function with 2 parameters returning a tuple
// The inverse function is [Eitherize2]
func Uneitherize2[F ~func(T0, T1) Either[error, R], T0, T1, R any](f F) func(T0, T1) (R, error) {
return func(t0 T0, t1 T1) (R, error) {
return UnwrapError(f(t0, t1))
}
}
// SequenceT2 converts 2 parameters of [Either[E, T]] into an [Either] of a [Tuple2].
func SequenceT2[E, T1, T2 any](t1 Either[E, T1], t2 Either[E, T2]) Either[E, T.Tuple2[T1, T2]] {
return A.SequenceT2(
Map[E, T1, func(T2) T.Tuple2[T1, T2]],
Ap[T.Tuple2[T1, T2], E, T2],
t1,
t2,
)
}
// SequenceTuple2 converts a [Tuple2] of [Either[E, T]] into an [Either[E, Tuple2]].
func SequenceTuple2[E, T1, T2 any](t T.Tuple2[Either[E, T1], Either[E, T2]]) Either[E, T.Tuple2[T1, T2]] {
return A.SequenceTuple2(
Map[E, T1, func(T2) T.Tuple2[T1, T2]],
Ap[T.Tuple2[T1, T2], E, T2],
t,
)
}
// TraverseTuple2 converts a [Tuple2] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple2]].
func TraverseTuple2[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], E, A1, T1, A2, T2 any](f1 F1, f2 F2) func (T.Tuple2[A1, A2]) Either[E, T.Tuple2[T1, T2]] {
return func(t T.Tuple2[A1, A2]) Either[E, T.Tuple2[T1, T2]] {
return A.TraverseTuple2(
Map[E, T1, func(T2) T.Tuple2[T1, T2]],
Ap[T.Tuple2[T1, T2], E, T2],
f1,
f2,
t,
)
}
}
// Eitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning an Either
// The inverse function is [Uneitherize3]
func Eitherize3[F ~func(T0, T1, T2) (R, error), T0, T1, T2, R any](f F) func(T0, T1, T2) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2)
})
}
}
// Uneitherize3 converts a function with 3 parameters returning an Either into a function with 3 parameters returning a tuple
// The inverse function is [Eitherize3]
func Uneitherize3[F ~func(T0, T1, T2) Either[error, R], T0, T1, T2, R any](f F) func(T0, T1, T2) (R, error) {
return func(t0 T0, t1 T1, t2 T2) (R, error) {
return UnwrapError(f(t0, t1, t2))
}
}
// SequenceT3 converts 3 parameters of [Either[E, T]] into an [Either] of a [Tuple3].
func SequenceT3[E, T1, T2, T3 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3]) Either[E, T.Tuple3[T1, T2, T3]] {
return A.SequenceT3(
Map[E, T1, func(T2) func(T3) T.Tuple3[T1, T2, T3]],
Ap[func(T3) T.Tuple3[T1, T2, T3], E, T2],
Ap[T.Tuple3[T1, T2, T3], E, T3],
t1,
t2,
t3,
)
}
// SequenceTuple3 converts a [Tuple3] of [Either[E, T]] into an [Either[E, Tuple3]].
func SequenceTuple3[E, T1, T2, T3 any](t T.Tuple3[Either[E, T1], Either[E, T2], Either[E, T3]]) Either[E, T.Tuple3[T1, T2, T3]] {
return A.SequenceTuple3(
Map[E, T1, func(T2) func(T3) T.Tuple3[T1, T2, T3]],
Ap[func(T3) T.Tuple3[T1, T2, T3], E, T2],
Ap[T.Tuple3[T1, T2, T3], E, T3],
t,
)
}
// TraverseTuple3 converts a [Tuple3] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple3]].
func TraverseTuple3[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], E, A1, T1, A2, T2, A3, T3 any](f1 F1, f2 F2, f3 F3) func (T.Tuple3[A1, A2, A3]) Either[E, T.Tuple3[T1, T2, T3]] {
return func(t T.Tuple3[A1, A2, A3]) Either[E, T.Tuple3[T1, T2, T3]] {
return A.TraverseTuple3(
Map[E, T1, func(T2) func(T3) T.Tuple3[T1, T2, T3]],
Ap[func(T3) T.Tuple3[T1, T2, T3], E, T2],
Ap[T.Tuple3[T1, T2, T3], E, T3],
f1,
f2,
f3,
t,
)
}
}
// Eitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning an Either
// The inverse function is [Uneitherize4]
func Eitherize4[F ~func(T0, T1, T2, T3) (R, error), T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3)
})
}
}
// Uneitherize4 converts a function with 4 parameters returning an Either into a function with 4 parameters returning a tuple
// The inverse function is [Eitherize4]
func Uneitherize4[F ~func(T0, T1, T2, T3) Either[error, R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3) (R, error) {
return UnwrapError(f(t0, t1, t2, t3))
}
}
// SequenceT4 converts 4 parameters of [Either[E, T]] into an [Either] of a [Tuple4].
func SequenceT4[E, T1, T2, T3, T4 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3], t4 Either[E, T4]) Either[E, T.Tuple4[T1, T2, T3, T4]] {
return A.SequenceT4(
Map[E, T1, func(T2) func(T3) func(T4) T.Tuple4[T1, T2, T3, T4]],
Ap[func(T3) func(T4) T.Tuple4[T1, T2, T3, T4], E, T2],
Ap[func(T4) T.Tuple4[T1, T2, T3, T4], E, T3],
Ap[T.Tuple4[T1, T2, T3, T4], E, T4],
t1,
t2,
t3,
t4,
)
}
// SequenceTuple4 converts a [Tuple4] of [Either[E, T]] into an [Either[E, Tuple4]].
func SequenceTuple4[E, T1, T2, T3, T4 any](t T.Tuple4[Either[E, T1], Either[E, T2], Either[E, T3], Either[E, T4]]) Either[E, T.Tuple4[T1, T2, T3, T4]] {
return A.SequenceTuple4(
Map[E, T1, func(T2) func(T3) func(T4) T.Tuple4[T1, T2, T3, T4]],
Ap[func(T3) func(T4) T.Tuple4[T1, T2, T3, T4], E, T2],
Ap[func(T4) T.Tuple4[T1, T2, T3, T4], E, T3],
Ap[T.Tuple4[T1, T2, T3, T4], E, T4],
t,
)
}
// TraverseTuple4 converts a [Tuple4] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple4]].
func TraverseTuple4[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], F4 ~func(A4) Either[E, T4], E, A1, T1, A2, T2, A3, T3, A4, T4 any](f1 F1, f2 F2, f3 F3, f4 F4) func (T.Tuple4[A1, A2, A3, A4]) Either[E, T.Tuple4[T1, T2, T3, T4]] {
return func(t T.Tuple4[A1, A2, A3, A4]) Either[E, T.Tuple4[T1, T2, T3, T4]] {
return A.TraverseTuple4(
Map[E, T1, func(T2) func(T3) func(T4) T.Tuple4[T1, T2, T3, T4]],
Ap[func(T3) func(T4) T.Tuple4[T1, T2, T3, T4], E, T2],
Ap[func(T4) T.Tuple4[T1, T2, T3, T4], E, T3],
Ap[T.Tuple4[T1, T2, T3, T4], E, T4],
f1,
f2,
f3,
f4,
t,
)
}
}
// Eitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning an Either
// The inverse function is [Uneitherize5]
func Eitherize5[F ~func(T0, T1, T2, T3, T4) (R, error), T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4)
})
}
}
// Uneitherize5 converts a function with 5 parameters returning an Either into a function with 5 parameters returning a tuple
// The inverse function is [Eitherize5]
func Uneitherize5[F ~func(T0, T1, T2, T3, T4) Either[error, R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4))
}
}
// SequenceT5 converts 5 parameters of [Either[E, T]] into an [Either] of a [Tuple5].
func SequenceT5[E, T1, T2, T3, T4, T5 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3], t4 Either[E, T4], t5 Either[E, T5]) Either[E, T.Tuple5[T1, T2, T3, T4, T5]] {
return A.SequenceT5(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5]],
Ap[func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T2],
Ap[func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T3],
Ap[func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T4],
Ap[T.Tuple5[T1, T2, T3, T4, T5], E, T5],
t1,
t2,
t3,
t4,
t5,
)
}
// SequenceTuple5 converts a [Tuple5] of [Either[E, T]] into an [Either[E, Tuple5]].
func SequenceTuple5[E, T1, T2, T3, T4, T5 any](t T.Tuple5[Either[E, T1], Either[E, T2], Either[E, T3], Either[E, T4], Either[E, T5]]) Either[E, T.Tuple5[T1, T2, T3, T4, T5]] {
return A.SequenceTuple5(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5]],
Ap[func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T2],
Ap[func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T3],
Ap[func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T4],
Ap[T.Tuple5[T1, T2, T3, T4, T5], E, T5],
t,
)
}
// TraverseTuple5 converts a [Tuple5] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple5]].
func TraverseTuple5[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], F4 ~func(A4) Either[E, T4], F5 ~func(A5) Either[E, T5], E, A1, T1, A2, T2, A3, T3, A4, T4, A5, T5 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) func (T.Tuple5[A1, A2, A3, A4, A5]) Either[E, T.Tuple5[T1, T2, T3, T4, T5]] {
return func(t T.Tuple5[A1, A2, A3, A4, A5]) Either[E, T.Tuple5[T1, T2, T3, T4, T5]] {
return A.TraverseTuple5(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5]],
Ap[func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T2],
Ap[func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T3],
Ap[func(T5) T.Tuple5[T1, T2, T3, T4, T5], E, T4],
Ap[T.Tuple5[T1, T2, T3, T4, T5], E, T5],
f1,
f2,
f3,
f4,
f5,
t,
)
}
}
// Eitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning an Either
// The inverse function is [Uneitherize6]
func Eitherize6[F ~func(T0, T1, T2, T3, T4, T5) (R, error), T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5)
})
}
}
// Uneitherize6 converts a function with 6 parameters returning an Either into a function with 6 parameters returning a tuple
// The inverse function is [Eitherize6]
func Uneitherize6[F ~func(T0, T1, T2, T3, T4, T5) Either[error, R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5))
}
}
// SequenceT6 converts 6 parameters of [Either[E, T]] into an [Either] of a [Tuple6].
func SequenceT6[E, T1, T2, T3, T4, T5, T6 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3], t4 Either[E, T4], t5 Either[E, T5], t6 Either[E, T6]) Either[E, T.Tuple6[T1, T2, T3, T4, T5, T6]] {
return A.SequenceT6(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6]],
Ap[func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T2],
Ap[func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T3],
Ap[func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T4],
Ap[func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T5],
Ap[T.Tuple6[T1, T2, T3, T4, T5, T6], E, T6],
t1,
t2,
t3,
t4,
t5,
t6,
)
}
// SequenceTuple6 converts a [Tuple6] of [Either[E, T]] into an [Either[E, Tuple6]].
func SequenceTuple6[E, T1, T2, T3, T4, T5, T6 any](t T.Tuple6[Either[E, T1], Either[E, T2], Either[E, T3], Either[E, T4], Either[E, T5], Either[E, T6]]) Either[E, T.Tuple6[T1, T2, T3, T4, T5, T6]] {
return A.SequenceTuple6(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6]],
Ap[func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T2],
Ap[func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T3],
Ap[func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T4],
Ap[func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T5],
Ap[T.Tuple6[T1, T2, T3, T4, T5, T6], E, T6],
t,
)
}
// TraverseTuple6 converts a [Tuple6] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple6]].
func TraverseTuple6[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], F4 ~func(A4) Either[E, T4], F5 ~func(A5) Either[E, T5], F6 ~func(A6) Either[E, T6], E, A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) func (T.Tuple6[A1, A2, A3, A4, A5, A6]) Either[E, T.Tuple6[T1, T2, T3, T4, T5, T6]] {
return func(t T.Tuple6[A1, A2, A3, A4, A5, A6]) Either[E, T.Tuple6[T1, T2, T3, T4, T5, T6]] {
return A.TraverseTuple6(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6]],
Ap[func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T2],
Ap[func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T3],
Ap[func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T4],
Ap[func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], E, T5],
Ap[T.Tuple6[T1, T2, T3, T4, T5, T6], E, T6],
f1,
f2,
f3,
f4,
f5,
f6,
t,
)
}
}
// Eitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning an Either
// The inverse function is [Uneitherize7]
func Eitherize7[F ~func(T0, T1, T2, T3, T4, T5, T6) (R, error), T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6)
})
}
}
// Uneitherize7 converts a function with 7 parameters returning an Either into a function with 7 parameters returning a tuple
// The inverse function is [Eitherize7]
func Uneitherize7[F ~func(T0, T1, T2, T3, T4, T5, T6) Either[error, R], T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6))
}
}
// SequenceT7 converts 7 parameters of [Either[E, T]] into an [Either] of a [Tuple7].
func SequenceT7[E, T1, T2, T3, T4, T5, T6, T7 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3], t4 Either[E, T4], t5 Either[E, T5], t6 Either[E, T6], t7 Either[E, T7]) Either[E, T.Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return A.SequenceT7(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T3],
Ap[func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T4],
Ap[func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T5],
Ap[func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T6],
Ap[T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T7],
t1,
t2,
t3,
t4,
t5,
t6,
t7,
)
}
// SequenceTuple7 converts a [Tuple7] of [Either[E, T]] into an [Either[E, Tuple7]].
func SequenceTuple7[E, T1, T2, T3, T4, T5, T6, T7 any](t T.Tuple7[Either[E, T1], Either[E, T2], Either[E, T3], Either[E, T4], Either[E, T5], Either[E, T6], Either[E, T7]]) Either[E, T.Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return A.SequenceTuple7(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T3],
Ap[func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T4],
Ap[func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T5],
Ap[func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T6],
Ap[T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T7],
t,
)
}
// TraverseTuple7 converts a [Tuple7] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple7]].
func TraverseTuple7[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], F4 ~func(A4) Either[E, T4], F5 ~func(A5) Either[E, T5], F6 ~func(A6) Either[E, T6], F7 ~func(A7) Either[E, T7], E, A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) func (T.Tuple7[A1, A2, A3, A4, A5, A6, A7]) Either[E, T.Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return func(t T.Tuple7[A1, A2, A3, A4, A5, A6, A7]) Either[E, T.Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return A.TraverseTuple7(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T3],
Ap[func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T4],
Ap[func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T5],
Ap[func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T6],
Ap[T.Tuple7[T1, T2, T3, T4, T5, T6, T7], E, T7],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
t,
)
}
}
// Eitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning an Either
// The inverse function is [Uneitherize8]
func Eitherize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7)
})
}
}
// Uneitherize8 converts a function with 8 parameters returning an Either into a function with 8 parameters returning a tuple
// The inverse function is [Eitherize8]
func Uneitherize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6, t7))
}
}
// SequenceT8 converts 8 parameters of [Either[E, T]] into an [Either] of a [Tuple8].
func SequenceT8[E, T1, T2, T3, T4, T5, T6, T7, T8 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3], t4 Either[E, T4], t5 Either[E, T5], t6 Either[E, T6], t7 Either[E, T7], t8 Either[E, T8]) Either[E, T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return A.SequenceT8(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T4],
Ap[func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T5],
Ap[func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T6],
Ap[func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T7],
Ap[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T8],
t1,
t2,
t3,
t4,
t5,
t6,
t7,
t8,
)
}
// SequenceTuple8 converts a [Tuple8] of [Either[E, T]] into an [Either[E, Tuple8]].
func SequenceTuple8[E, T1, T2, T3, T4, T5, T6, T7, T8 any](t T.Tuple8[Either[E, T1], Either[E, T2], Either[E, T3], Either[E, T4], Either[E, T5], Either[E, T6], Either[E, T7], Either[E, T8]]) Either[E, T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return A.SequenceTuple8(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T4],
Ap[func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T5],
Ap[func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T6],
Ap[func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T7],
Ap[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T8],
t,
)
}
// TraverseTuple8 converts a [Tuple8] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple8]].
func TraverseTuple8[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], F4 ~func(A4) Either[E, T4], F5 ~func(A5) Either[E, T5], F6 ~func(A6) Either[E, T6], F7 ~func(A7) Either[E, T7], F8 ~func(A8) Either[E, T8], E, A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) func (T.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) Either[E, T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return func(t T.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) Either[E, T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return A.TraverseTuple8(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T4],
Ap[func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T5],
Ap[func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T6],
Ap[func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T7],
Ap[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], E, T8],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
t,
)
}
}
// Eitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning an Either
// The inverse function is [Uneitherize9]
func Eitherize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8)
})
}
}
// Uneitherize9 converts a function with 9 parameters returning an Either into a function with 9 parameters returning a tuple
// The inverse function is [Eitherize9]
func Uneitherize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6, t7, t8))
}
}
// SequenceT9 converts 9 parameters of [Either[E, T]] into an [Either] of a [Tuple9].
func SequenceT9[E, T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3], t4 Either[E, T4], t5 Either[E, T5], t6 Either[E, T6], t7 Either[E, T7], t8 Either[E, T8], t9 Either[E, T9]) Either[E, T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return A.SequenceT9(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T4],
Ap[func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T5],
Ap[func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T6],
Ap[func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T7],
Ap[func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T8],
Ap[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T9],
t1,
t2,
t3,
t4,
t5,
t6,
t7,
t8,
t9,
)
}
// SequenceTuple9 converts a [Tuple9] of [Either[E, T]] into an [Either[E, Tuple9]].
func SequenceTuple9[E, T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t T.Tuple9[Either[E, T1], Either[E, T2], Either[E, T3], Either[E, T4], Either[E, T5], Either[E, T6], Either[E, T7], Either[E, T8], Either[E, T9]]) Either[E, T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return A.SequenceTuple9(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T4],
Ap[func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T5],
Ap[func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T6],
Ap[func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T7],
Ap[func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T8],
Ap[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T9],
t,
)
}
// TraverseTuple9 converts a [Tuple9] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple9]].
func TraverseTuple9[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], F4 ~func(A4) Either[E, T4], F5 ~func(A5) Either[E, T5], F6 ~func(A6) Either[E, T6], F7 ~func(A7) Either[E, T7], F8 ~func(A8) Either[E, T8], F9 ~func(A9) Either[E, T9], E, A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8, A9, T9 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) func (T.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) Either[E, T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return func(t T.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) Either[E, T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return A.TraverseTuple9(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T4],
Ap[func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T5],
Ap[func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T6],
Ap[func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T7],
Ap[func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T8],
Ap[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], E, T9],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f9,
t,
)
}
}
// Eitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning an Either
// The inverse function is [Uneitherize10]
func Eitherize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Either[error, R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) Either[error, R] {
return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
})
}
}
// Uneitherize10 converts a function with 10 parameters returning an Either into a function with 10 parameters returning a tuple
// The inverse function is [Eitherize10]
func Uneitherize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
}
}
// SequenceT10 converts 10 parameters of [Either[E, T]] into an [Either] of a [Tuple10].
func SequenceT10[E, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t1 Either[E, T1], t2 Either[E, T2], t3 Either[E, T3], t4 Either[E, T4], t5 Either[E, T5], t6 Either[E, T6], t7 Either[E, T7], t8 Either[E, T8], t9 Either[E, T9], t10 Either[E, T10]) Either[E, T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return A.SequenceT10(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T4],
Ap[func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T5],
Ap[func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T6],
Ap[func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T7],
Ap[func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T8],
Ap[func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T9],
Ap[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T10],
t1,
t2,
t3,
t4,
t5,
t6,
t7,
t8,
t9,
t10,
)
}
// SequenceTuple10 converts a [Tuple10] of [Either[E, T]] into an [Either[E, Tuple10]].
func SequenceTuple10[E, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t T.Tuple10[Either[E, T1], Either[E, T2], Either[E, T3], Either[E, T4], Either[E, T5], Either[E, T6], Either[E, T7], Either[E, T8], Either[E, T9], Either[E, T10]]) Either[E, T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return A.SequenceTuple10(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T4],
Ap[func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T5],
Ap[func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T6],
Ap[func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T7],
Ap[func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T8],
Ap[func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T9],
Ap[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T10],
t,
)
}
// TraverseTuple10 converts a [Tuple10] of [A] via transformation functions transforming [A] to [Either[E, A]] into a [Either[E, Tuple10]].
func TraverseTuple10[F1 ~func(A1) Either[E, T1], F2 ~func(A2) Either[E, T2], F3 ~func(A3) Either[E, T3], F4 ~func(A4) Either[E, T4], F5 ~func(A5) Either[E, T5], F6 ~func(A6) Either[E, T6], F7 ~func(A7) Either[E, T7], F8 ~func(A8) Either[E, T8], F9 ~func(A9) Either[E, T9], F10 ~func(A10) Either[E, T10], E, A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8, A9, T9, A10, T10 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) func (T.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) Either[E, T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return func(t T.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) Either[E, T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return A.TraverseTuple10(
Map[E, T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T4],
Ap[func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T5],
Ap[func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T6],
Ap[func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T7],
Ap[func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T8],
Ap[func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T9],
Ap[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], E, T10],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f9,
f10,
t,
)
}
}

View File

@@ -1,45 +0,0 @@
package either
import (
"github.com/ibm/fp-go/internal/apply"
T "github.com/ibm/fp-go/tuple"
)
// SequenceT converts n inputs of higher kinded types into a higher kinded types of n strongly typed values, represented as a tuple
func SequenceT1[E, A any](a Either[E, A]) Either[E, T.Tuple1[A]] {
return apply.SequenceT1(
Map[E, A, T.Tuple1[A]],
a,
)
}
func SequenceT2[E, A, B any](a Either[E, A], b Either[E, B]) Either[E, T.Tuple2[A, B]] {
return apply.SequenceT2(
Map[E, A, func(B) T.Tuple2[A, B]],
Ap[T.Tuple2[A, B], E, B],
a, b,
)
}
func SequenceT3[E, A, B, C any](a Either[E, A], b Either[E, B], c Either[E, C]) Either[E, T.Tuple3[A, B, C]] {
return apply.SequenceT3(
Map[E, A, func(B) func(C) T.Tuple3[A, B, C]],
Ap[func(C) T.Tuple3[A, B, C], E, B],
Ap[T.Tuple3[A, B, C], E, C],
a, b, c,
)
}
func SequenceT4[E, A, B, C, D any](a Either[E, A], b Either[E, B], c Either[E, C], d Either[E, D]) Either[E, T.Tuple4[A, B, C, D]] {
return apply.SequenceT4(
Map[E, A, func(B) func(C) func(D) T.Tuple4[A, B, C, D]],
Ap[func(C) func(D) T.Tuple4[A, B, C, D], E, B],
Ap[func(D) T.Tuple4[A, B, C, D], E, C],
Ap[T.Tuple4[A, B, C, D], E, D],
a, b, c, d,
)
}

View File

@@ -1,454 +1,450 @@
// 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-14 13:19:42.9896471 +0200 CEST m=+0.009694501 // 2023-07-17 13:23:07.340967 +0200 CEST m=+0.009883801
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

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,3 @@
package option package option
//go:generate go run .. option --count 10 --filename optionize.go //go:generate go run .. option --count 10 --filename gen.go

518
option/gen.go Normal file
View File

@@ -0,0 +1,518 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2023-07-17 13:23:13.386184 +0200 CEST m=+0.015046301
package option
import (
A "github.com/ibm/fp-go/internal/apply"
T "github.com/ibm/fp-go/tuple"
)
// optionize converts a nullary function to an option
func optionize[R any](f func() (R, bool)) Option[R] {
if r, ok := f(); ok {
return Some(r)
}
return None[R]()
}
// Optionize0 converts a function with 0 parameters returning a tuple of a return value R and a boolean into a function with 0 parameters returning an Option[R]
func Optionize0[F ~func() (R, bool), R any](f F) func() Option[R] {
return func() Option[R] {
return optionize(func() (R, bool) {
return f()
})
}
}
// Unoptionize0 converts a function with 0 parameters returning a tuple of a return value R and a boolean into a function with 0 parameters returning an Option[R]
func Unoptionize0[F ~func() Option[R], R any](f F) func() (R, bool) {
return func() (R, bool) {
return Unwrap(f())
}
}
// Optionize1 converts a function with 1 parameters returning a tuple of a return value R and a boolean into a function with 1 parameters returning an Option[R]
func Optionize1[F ~func(T0) (R, bool), T0, R any](f F) func(T0) Option[R] {
return func(t0 T0) Option[R] {
return optionize(func() (R, bool) {
return f(t0)
})
}
}
// Unoptionize1 converts a function with 1 parameters returning a tuple of a return value R and a boolean into a function with 1 parameters returning an Option[R]
func Unoptionize1[F ~func(T0) Option[R], T0, R any](f F) func(T0) (R, bool) {
return func(t0 T0) (R, bool) {
return Unwrap(f(t0))
}
}
// SequenceTuple1 converts a [Tuple1] of [Option[T]] into an [Option[Tuple1]].
func SequenceTuple1[T1 any](t T.Tuple1[Option[T1]]) Option[T.Tuple1[T1]] {
return A.SequenceTuple1(
Map[T1, T.Tuple1[T1]],
t,
)
}
// TraverseTuple1 converts a [Tuple1] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple1]].
func TraverseTuple1[F1 ~func(A1) Option[T1], A1, T1 any](f1 F1) func (T.Tuple1[A1]) Option[T.Tuple1[T1]] {
return func(t T.Tuple1[A1]) Option[T.Tuple1[T1]] {
return A.TraverseTuple1(
Map[T1, T.Tuple1[T1]],
f1,
t,
)
}
}
// Optionize2 converts a function with 2 parameters returning a tuple of a return value R and a boolean into a function with 2 parameters returning an Option[R]
func Optionize2[F ~func(T0, T1) (R, bool), T0, T1, R any](f F) func(T0, T1) Option[R] {
return func(t0 T0, t1 T1) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1)
})
}
}
// Unoptionize2 converts a function with 2 parameters returning a tuple of a return value R and a boolean into a function with 2 parameters returning an Option[R]
func Unoptionize2[F ~func(T0, T1) Option[R], T0, T1, R any](f F) func(T0, T1) (R, bool) {
return func(t0 T0, t1 T1) (R, bool) {
return Unwrap(f(t0, t1))
}
}
// SequenceTuple2 converts a [Tuple2] of [Option[T]] into an [Option[Tuple2]].
func SequenceTuple2[T1, T2 any](t T.Tuple2[Option[T1], Option[T2]]) Option[T.Tuple2[T1, T2]] {
return A.SequenceTuple2(
Map[T1, func(T2) T.Tuple2[T1, T2]],
Ap[T.Tuple2[T1, T2], T2],
t,
)
}
// TraverseTuple2 converts a [Tuple2] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple2]].
func TraverseTuple2[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], A1, T1, A2, T2 any](f1 F1, f2 F2) func (T.Tuple2[A1, A2]) Option[T.Tuple2[T1, T2]] {
return func(t T.Tuple2[A1, A2]) Option[T.Tuple2[T1, T2]] {
return A.TraverseTuple2(
Map[T1, func(T2) T.Tuple2[T1, T2]],
Ap[T.Tuple2[T1, T2], T2],
f1,
f2,
t,
)
}
}
// Optionize3 converts a function with 3 parameters returning a tuple of a return value R and a boolean into a function with 3 parameters returning an Option[R]
func Optionize3[F ~func(T0, T1, T2) (R, bool), T0, T1, T2, R any](f F) func(T0, T1, T2) Option[R] {
return func(t0 T0, t1 T1, t2 T2) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2)
})
}
}
// Unoptionize3 converts a function with 3 parameters returning a tuple of a return value R and a boolean into a function with 3 parameters returning an Option[R]
func Unoptionize3[F ~func(T0, T1, T2) Option[R], T0, T1, T2, R any](f F) func(T0, T1, T2) (R, bool) {
return func(t0 T0, t1 T1, t2 T2) (R, bool) {
return Unwrap(f(t0, t1, t2))
}
}
// SequenceTuple3 converts a [Tuple3] of [Option[T]] into an [Option[Tuple3]].
func SequenceTuple3[T1, T2, T3 any](t T.Tuple3[Option[T1], Option[T2], Option[T3]]) Option[T.Tuple3[T1, T2, T3]] {
return A.SequenceTuple3(
Map[T1, func(T2) func(T3) T.Tuple3[T1, T2, T3]],
Ap[func(T3) T.Tuple3[T1, T2, T3], T2],
Ap[T.Tuple3[T1, T2, T3], T3],
t,
)
}
// TraverseTuple3 converts a [Tuple3] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple3]].
func TraverseTuple3[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], A1, T1, A2, T2, A3, T3 any](f1 F1, f2 F2, f3 F3) func (T.Tuple3[A1, A2, A3]) Option[T.Tuple3[T1, T2, T3]] {
return func(t T.Tuple3[A1, A2, A3]) Option[T.Tuple3[T1, T2, T3]] {
return A.TraverseTuple3(
Map[T1, func(T2) func(T3) T.Tuple3[T1, T2, T3]],
Ap[func(T3) T.Tuple3[T1, T2, T3], T2],
Ap[T.Tuple3[T1, T2, T3], T3],
f1,
f2,
f3,
t,
)
}
}
// Optionize4 converts a function with 4 parameters returning a tuple of a return value R and a boolean into a function with 4 parameters returning an Option[R]
func Optionize4[F ~func(T0, T1, T2, T3) (R, bool), T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3)
})
}
}
// Unoptionize4 converts a function with 4 parameters returning a tuple of a return value R and a boolean into a function with 4 parameters returning an Option[R]
func Unoptionize4[F ~func(T0, T1, T2, T3) Option[R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3) (R, bool) {
return Unwrap(f(t0, t1, t2, t3))
}
}
// SequenceTuple4 converts a [Tuple4] of [Option[T]] into an [Option[Tuple4]].
func SequenceTuple4[T1, T2, T3, T4 any](t T.Tuple4[Option[T1], Option[T2], Option[T3], Option[T4]]) Option[T.Tuple4[T1, T2, T3, T4]] {
return A.SequenceTuple4(
Map[T1, func(T2) func(T3) func(T4) T.Tuple4[T1, T2, T3, T4]],
Ap[func(T3) func(T4) T.Tuple4[T1, T2, T3, T4], T2],
Ap[func(T4) T.Tuple4[T1, T2, T3, T4], T3],
Ap[T.Tuple4[T1, T2, T3, T4], T4],
t,
)
}
// TraverseTuple4 converts a [Tuple4] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple4]].
func TraverseTuple4[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], A1, T1, A2, T2, A3, T3, A4, T4 any](f1 F1, f2 F2, f3 F3, f4 F4) func (T.Tuple4[A1, A2, A3, A4]) Option[T.Tuple4[T1, T2, T3, T4]] {
return func(t T.Tuple4[A1, A2, A3, A4]) Option[T.Tuple4[T1, T2, T3, T4]] {
return A.TraverseTuple4(
Map[T1, func(T2) func(T3) func(T4) T.Tuple4[T1, T2, T3, T4]],
Ap[func(T3) func(T4) T.Tuple4[T1, T2, T3, T4], T2],
Ap[func(T4) T.Tuple4[T1, T2, T3, T4], T3],
Ap[T.Tuple4[T1, T2, T3, T4], T4],
f1,
f2,
f3,
f4,
t,
)
}
}
// Optionize5 converts a function with 5 parameters returning a tuple of a return value R and a boolean into a function with 5 parameters returning an Option[R]
func Optionize5[F ~func(T0, T1, T2, T3, T4) (R, bool), T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4)
})
}
}
// Unoptionize5 converts a function with 5 parameters returning a tuple of a return value R and a boolean into a function with 5 parameters returning an Option[R]
func Unoptionize5[F ~func(T0, T1, T2, T3, T4) Option[R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4))
}
}
// SequenceTuple5 converts a [Tuple5] of [Option[T]] into an [Option[Tuple5]].
func SequenceTuple5[T1, T2, T3, T4, T5 any](t T.Tuple5[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5]]) Option[T.Tuple5[T1, T2, T3, T4, T5]] {
return A.SequenceTuple5(
Map[T1, func(T2) func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5]],
Ap[func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], T2],
Ap[func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], T3],
Ap[func(T5) T.Tuple5[T1, T2, T3, T4, T5], T4],
Ap[T.Tuple5[T1, T2, T3, T4, T5], T5],
t,
)
}
// TraverseTuple5 converts a [Tuple5] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple5]].
func TraverseTuple5[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) func (T.Tuple5[A1, A2, A3, A4, A5]) Option[T.Tuple5[T1, T2, T3, T4, T5]] {
return func(t T.Tuple5[A1, A2, A3, A4, A5]) Option[T.Tuple5[T1, T2, T3, T4, T5]] {
return A.TraverseTuple5(
Map[T1, func(T2) func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5]],
Ap[func(T3) func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], T2],
Ap[func(T4) func(T5) T.Tuple5[T1, T2, T3, T4, T5], T3],
Ap[func(T5) T.Tuple5[T1, T2, T3, T4, T5], T4],
Ap[T.Tuple5[T1, T2, T3, T4, T5], T5],
f1,
f2,
f3,
f4,
f5,
t,
)
}
}
// Optionize6 converts a function with 6 parameters returning a tuple of a return value R and a boolean into a function with 6 parameters returning an Option[R]
func Optionize6[F ~func(T0, T1, T2, T3, T4, T5) (R, bool), T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5)
})
}
}
// Unoptionize6 converts a function with 6 parameters returning a tuple of a return value R and a boolean into a function with 6 parameters returning an Option[R]
func Unoptionize6[F ~func(T0, T1, T2, T3, T4, T5) Option[R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5))
}
}
// SequenceTuple6 converts a [Tuple6] of [Option[T]] into an [Option[Tuple6]].
func SequenceTuple6[T1, T2, T3, T4, T5, T6 any](t T.Tuple6[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6]]) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]] {
return A.SequenceTuple6(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6]],
Ap[func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T2],
Ap[func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T3],
Ap[func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T4],
Ap[func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T5],
Ap[T.Tuple6[T1, T2, T3, T4, T5, T6], T6],
t,
)
}
// TraverseTuple6 converts a [Tuple6] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple6]].
func TraverseTuple6[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) func (T.Tuple6[A1, A2, A3, A4, A5, A6]) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]] {
return func(t T.Tuple6[A1, A2, A3, A4, A5, A6]) Option[T.Tuple6[T1, T2, T3, T4, T5, T6]] {
return A.TraverseTuple6(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6]],
Ap[func(T3) func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T2],
Ap[func(T4) func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T3],
Ap[func(T5) func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T4],
Ap[func(T6) T.Tuple6[T1, T2, T3, T4, T5, T6], T5],
Ap[T.Tuple6[T1, T2, T3, T4, T5, T6], T6],
f1,
f2,
f3,
f4,
f5,
f6,
t,
)
}
}
// Optionize7 converts a function with 7 parameters returning a tuple of a return value R and a boolean into a function with 7 parameters returning an Option[R]
func Optionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) (R, bool), T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6)
})
}
}
// Unoptionize7 converts a function with 7 parameters returning a tuple of a return value R and a boolean into a function with 7 parameters returning an Option[R]
func Unoptionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) Option[R], T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6))
}
}
// SequenceTuple7 converts a [Tuple7] of [Option[T]] into an [Option[Tuple7]].
func SequenceTuple7[T1, T2, T3, T4, T5, T6, T7 any](t T.Tuple7[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7]]) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return A.SequenceTuple7(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T2],
Ap[func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T3],
Ap[func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T4],
Ap[func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T5],
Ap[func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T6],
Ap[T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T7],
t,
)
}
// TraverseTuple7 converts a [Tuple7] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple7]].
func TraverseTuple7[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) func (T.Tuple7[A1, A2, A3, A4, A5, A6, A7]) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return func(t T.Tuple7[A1, A2, A3, A4, A5, A6, A7]) Option[T.Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return A.TraverseTuple7(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T2],
Ap[func(T4) func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T3],
Ap[func(T5) func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T4],
Ap[func(T6) func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T5],
Ap[func(T7) T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T6],
Ap[T.Tuple7[T1, T2, T3, T4, T5, T6, T7], T7],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
t,
)
}
}
// Optionize8 converts a function with 8 parameters returning a tuple of a return value R and a boolean into a function with 8 parameters returning an Option[R]
func Optionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7)
})
}
}
// Unoptionize8 converts a function with 8 parameters returning a tuple of a return value R and a boolean into a function with 8 parameters returning an Option[R]
func Unoptionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6, t7))
}
}
// SequenceTuple8 converts a [Tuple8] of [Option[T]] into an [Option[Tuple8]].
func SequenceTuple8[T1, T2, T3, T4, T5, T6, T7, T8 any](t T.Tuple8[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7], Option[T8]]) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return A.SequenceTuple8(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T3],
Ap[func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T4],
Ap[func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T5],
Ap[func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T6],
Ap[func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T7],
Ap[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T8],
t,
)
}
// TraverseTuple8 converts a [Tuple8] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple8]].
func TraverseTuple8[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], F8 ~func(A8) Option[T8], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) func (T.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return func(t T.Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]) Option[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return A.TraverseTuple8(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T3],
Ap[func(T5) func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T4],
Ap[func(T6) func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T5],
Ap[func(T7) func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T6],
Ap[func(T8) T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T7],
Ap[T.Tuple8[T1, T2, T3, T4, T5, T6, T7, T8], T8],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
t,
)
}
}
// Optionize9 converts a function with 9 parameters returning a tuple of a return value R and a boolean into a function with 9 parameters returning an Option[R]
func Optionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8)
})
}
}
// Unoptionize9 converts a function with 9 parameters returning a tuple of a return value R and a boolean into a function with 9 parameters returning an Option[R]
func Unoptionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6, t7, t8))
}
}
// SequenceTuple9 converts a [Tuple9] of [Option[T]] into an [Option[Tuple9]].
func SequenceTuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t T.Tuple9[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7], Option[T8], Option[T9]]) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return A.SequenceTuple9(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T4],
Ap[func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T5],
Ap[func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T6],
Ap[func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T7],
Ap[func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T8],
Ap[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T9],
t,
)
}
// TraverseTuple9 converts a [Tuple9] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple9]].
func TraverseTuple9[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], F8 ~func(A8) Option[T8], F9 ~func(A9) Option[T9], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8, A9, T9 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) func (T.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return func(t T.Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]) Option[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return A.TraverseTuple9(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T4],
Ap[func(T6) func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T5],
Ap[func(T7) func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T6],
Ap[func(T8) func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T7],
Ap[func(T9) T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T8],
Ap[T.Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9], T9],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f9,
t,
)
}
}
// Optionize10 converts a function with 10 parameters returning a tuple of a return value R and a boolean into a function with 10 parameters returning an Option[R]
func Optionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
})
}
}
// Unoptionize10 converts a function with 10 parameters returning a tuple of a return value R and a boolean into a function with 10 parameters returning an Option[R]
func Unoptionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
}
}
// SequenceTuple10 converts a [Tuple10] of [Option[T]] into an [Option[Tuple10]].
func SequenceTuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t T.Tuple10[Option[T1], Option[T2], Option[T3], Option[T4], Option[T5], Option[T6], Option[T7], Option[T8], Option[T9], Option[T10]]) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return A.SequenceTuple10(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T4],
Ap[func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T5],
Ap[func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T6],
Ap[func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T7],
Ap[func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T8],
Ap[func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T9],
Ap[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T10],
t,
)
}
// TraverseTuple10 converts a [Tuple10] of [A] via transformation functions transforming [A] to [Option[A]] into a [Option[Tuple10]].
func TraverseTuple10[F1 ~func(A1) Option[T1], F2 ~func(A2) Option[T2], F3 ~func(A3) Option[T3], F4 ~func(A4) Option[T4], F5 ~func(A5) Option[T5], F6 ~func(A6) Option[T6], F7 ~func(A7) Option[T7], F8 ~func(A8) Option[T8], F9 ~func(A9) Option[T9], F10 ~func(A10) Option[T10], A1, T1, A2, T2, A3, T3, A4, T4, A5, T5, A6, T6, A7, T7, A8, T8, A9, T9, A10, T10 any](f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) func (T.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return func(t T.Tuple10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]) Option[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return A.TraverseTuple10(
Map[T1, func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]],
Ap[func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T2],
Ap[func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T3],
Ap[func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T4],
Ap[func(T6) func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T5],
Ap[func(T7) func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T6],
Ap[func(T8) func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T7],
Ap[func(T9) func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T8],
Ap[func(T10) T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T9],
Ap[T.Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], T10],
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8,
f9,
f10,
t,
)
}
}

View File

@@ -1,188 +0,0 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2023-07-14 13:19:45.9328857 +0200 CEST m=+0.012986701
package option
// optionize converts a nullary function to an option
func optionize[R any](f func() (R, bool)) Option[R] {
if r, ok := f(); ok {
return Some(r)
}
return None[R]()
}
// Optionize0 converts a function with 0 parameters returning a tuple of a return value R and a boolean into a function with 0 parameters returning an Option[R]
func Optionize0[F ~func() (R, bool), R any](f F) func() Option[R] {
return func() Option[R] {
return optionize(func() (R, bool) {
return f()
})
}
}
// Unoptionize0 converts a function with 0 parameters returning a tuple of a return value R and a boolean into a function with 0 parameters returning an Option[R]
func Unoptionize0[F ~func() Option[R], R any](f F) func() (R, bool) {
return func() (R, bool) {
return Unwrap(f())
}
}
// Optionize1 converts a function with 1 parameters returning a tuple of a return value R and a boolean into a function with 1 parameters returning an Option[R]
func Optionize1[F ~func(T0) (R, bool), T0, R any](f F) func(T0) Option[R] {
return func(t0 T0) Option[R] {
return optionize(func() (R, bool) {
return f(t0)
})
}
}
// Unoptionize1 converts a function with 1 parameters returning a tuple of a return value R and a boolean into a function with 1 parameters returning an Option[R]
func Unoptionize1[F ~func(T0) Option[R], T0, R any](f F) func(T0) (R, bool) {
return func(t0 T0) (R, bool) {
return Unwrap(f(t0))
}
}
// Optionize2 converts a function with 2 parameters returning a tuple of a return value R and a boolean into a function with 2 parameters returning an Option[R]
func Optionize2[F ~func(T0, T1) (R, bool), T0, T1, R any](f F) func(T0, T1) Option[R] {
return func(t0 T0, t1 T1) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1)
})
}
}
// Unoptionize2 converts a function with 2 parameters returning a tuple of a return value R and a boolean into a function with 2 parameters returning an Option[R]
func Unoptionize2[F ~func(T0, T1) Option[R], T0, T1, R any](f F) func(T0, T1) (R, bool) {
return func(t0 T0, t1 T1) (R, bool) {
return Unwrap(f(t0, t1))
}
}
// Optionize3 converts a function with 3 parameters returning a tuple of a return value R and a boolean into a function with 3 parameters returning an Option[R]
func Optionize3[F ~func(T0, T1, T2) (R, bool), T0, T1, T2, R any](f F) func(T0, T1, T2) Option[R] {
return func(t0 T0, t1 T1, t2 T2) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2)
})
}
}
// Unoptionize3 converts a function with 3 parameters returning a tuple of a return value R and a boolean into a function with 3 parameters returning an Option[R]
func Unoptionize3[F ~func(T0, T1, T2) Option[R], T0, T1, T2, R any](f F) func(T0, T1, T2) (R, bool) {
return func(t0 T0, t1 T1, t2 T2) (R, bool) {
return Unwrap(f(t0, t1, t2))
}
}
// Optionize4 converts a function with 4 parameters returning a tuple of a return value R and a boolean into a function with 4 parameters returning an Option[R]
func Optionize4[F ~func(T0, T1, T2, T3) (R, bool), T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3)
})
}
}
// Unoptionize4 converts a function with 4 parameters returning a tuple of a return value R and a boolean into a function with 4 parameters returning an Option[R]
func Unoptionize4[F ~func(T0, T1, T2, T3) Option[R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3) (R, bool) {
return Unwrap(f(t0, t1, t2, t3))
}
}
// Optionize5 converts a function with 5 parameters returning a tuple of a return value R and a boolean into a function with 5 parameters returning an Option[R]
func Optionize5[F ~func(T0, T1, T2, T3, T4) (R, bool), T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4)
})
}
}
// Unoptionize5 converts a function with 5 parameters returning a tuple of a return value R and a boolean into a function with 5 parameters returning an Option[R]
func Unoptionize5[F ~func(T0, T1, T2, T3, T4) Option[R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4))
}
}
// Optionize6 converts a function with 6 parameters returning a tuple of a return value R and a boolean into a function with 6 parameters returning an Option[R]
func Optionize6[F ~func(T0, T1, T2, T3, T4, T5) (R, bool), T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5)
})
}
}
// Unoptionize6 converts a function with 6 parameters returning a tuple of a return value R and a boolean into a function with 6 parameters returning an Option[R]
func Unoptionize6[F ~func(T0, T1, T2, T3, T4, T5) Option[R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5))
}
}
// Optionize7 converts a function with 7 parameters returning a tuple of a return value R and a boolean into a function with 7 parameters returning an Option[R]
func Optionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) (R, bool), T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6)
})
}
}
// Unoptionize7 converts a function with 7 parameters returning a tuple of a return value R and a boolean into a function with 7 parameters returning an Option[R]
func Unoptionize7[F ~func(T0, T1, T2, T3, T4, T5, T6) Option[R], T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6))
}
}
// Optionize8 converts a function with 8 parameters returning a tuple of a return value R and a boolean into a function with 8 parameters returning an Option[R]
func Optionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7)
})
}
}
// Unoptionize8 converts a function with 8 parameters returning a tuple of a return value R and a boolean into a function with 8 parameters returning an Option[R]
func Unoptionize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6, t7))
}
}
// Optionize9 converts a function with 9 parameters returning a tuple of a return value R and a boolean into a function with 9 parameters returning an Option[R]
func Optionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8)
})
}
}
// Unoptionize9 converts a function with 9 parameters returning a tuple of a return value R and a boolean into a function with 9 parameters returning an Option[R]
func Unoptionize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6, t7, t8))
}
}
// Optionize10 converts a function with 10 parameters returning a tuple of a return value R and a boolean into a function with 10 parameters returning an Option[R]
func Optionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool), T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R] {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) Option[R] {
return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
})
}
}
// Unoptionize10 converts a function with 10 parameters returning a tuple of a return value R and a boolean into a function with 10 parameters returning an Option[R]
func Unoptionize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) Option[R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, bool) {
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
}
}

File diff suppressed because it is too large Load Diff