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

fix: code generation for tuple

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-13 17:34:13 +02:00
parent b34f3e3ae1
commit a18a04ce39
13 changed files with 2040 additions and 1371 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
fp-go.exe

View File

@ -9,5 +9,6 @@ func Commands() []*C.Command {
PipeCommand(), PipeCommand(),
OptionCommand(), OptionCommand(),
EitherCommand(), EitherCommand(),
TupleCommand(),
} }
} }

View File

@ -12,7 +12,7 @@ import (
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", 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)
fmt.Fprintf(f, "func Uneitherize%d[F ~func(", i) fmt.Fprintf(f, "func Uneitherize%d[F ~func(", i)
for j := 0; j < i; j++ { for j := 0; j < i; j++ {
if j > 0 { if j > 0 {
@ -54,7 +54,7 @@ func generateUneitherize(f *os.File, i int) {
func generateEitherize(f *os.File, i int) { func generateEitherize(f *os.File, i int) {
// Create the optionize version // Create the optionize version
fmt.Fprintf(f, "\n// Eitherize%d converts a function with %d parameters returning a tuple into a function with %d parameters returning an Either\n", i, i, i) fmt.Fprintf(f, "\n// Eitherize%d converts a function with %d parameters returning a tuple into a function with %d parameters returning an Either\n// The inverse function is [Uneitherize%d]\n", i, i, i, i)
fmt.Fprintf(f, "func Eitherize%d[F ~func(", i) fmt.Fprintf(f, "func Eitherize%d[F ~func(", i)
for j := 0; j < i; j++ { for j := 0; j < i; j++ {
if j > 0 { if j > 0 {

323
cli/tuple.go Normal file
View File

@ -0,0 +1,323 @@
package cli
import (
"fmt"
"log"
"os"
"path/filepath"
"time"
C "github.com/urfave/cli/v2"
)
func writeTupleType(f *os.File, i int) {
fmt.Fprintf(f, "Tuple%d[", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j)
}
fmt.Fprintf(f, "]")
}
func generateMonoid(f *os.File, i int) {
// 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, "func Monoid%d[", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j)
}
fmt.Fprintf(f, " any](")
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "m%d M.Monoid[T%d]", j, j)
}
fmt.Fprintf(f, ") M.Monoid[")
writeTupleType(f, i)
fmt.Fprintf(f, "] {\n")
fmt.Fprintf(f, " return M.MakeMonoid(func(l, r ")
writeTupleType(f, i)
fmt.Fprintf(f, ") ")
writeTupleType(f, i)
fmt.Fprintf(f, "{\n")
fmt.Fprintf(f, " return MakeTuple%d(", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "m%d.Concat(l.F%d, r.F%d)", j, j, j)
}
fmt.Fprintf(f, ")\n")
fmt.Fprintf(f, " }, MakeTuple%d(", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "m%d.Empty()", j)
}
fmt.Fprintf(f, "))\n")
fmt.Fprintf(f, "}\n")
}
func generateOrd(f *os.File, i int) {
// Create the optionize version
fmt.Fprintf(f, "\n// Ord%d creates n [Ord] for a [Tuple%d] based on %d [Ord]s for the contained types\n", i, i, i)
fmt.Fprintf(f, "func Ord%d[", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j)
}
fmt.Fprintf(f, " any](")
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "o%d O.Ord[T%d]", j, j)
}
fmt.Fprintf(f, ") O.Ord[")
writeTupleType(f, i)
fmt.Fprintf(f, "] {\n")
fmt.Fprintf(f, " return O.MakeOrd(func(l, r ")
writeTupleType(f, i)
fmt.Fprintf(f, ") int {\n")
for j := 1; j <= i; j++ {
fmt.Fprintf(f, " if c:= o%d.Compare(l.F%d, r.F%d); c != 0 {return c}\n", j, j, j)
}
fmt.Fprintf(f, " return 0\n")
fmt.Fprintf(f, " }, func(l, r ")
writeTupleType(f, i)
fmt.Fprintf(f, ") bool {\n")
fmt.Fprintf(f, " return ")
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, " && ")
}
fmt.Fprintf(f, "o%d.Equals(l.F%d, r.F%d)", j, j, j)
}
fmt.Fprintf(f, "\n")
fmt.Fprintf(f, " })\n")
fmt.Fprintf(f, "}\n")
}
func generateTupleType(f *os.File, i int) {
// Create the optionize version
fmt.Fprintf(f, "\n// Tuple%d is a struct that carries %d independently typed values\n", i, i)
fmt.Fprintf(f, "type Tuple%d[", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j)
}
fmt.Fprintf(f, " any] struct {\n")
for j := 1; j <= i; j++ {
fmt.Fprintf(f, " F%d T%d\n", j, j)
}
fmt.Fprintf(f, "}\n")
}
func generateMakeTupleType(f *os.File, i int) {
// Create the optionize version
fmt.Fprintf(f, "\n// MakeTuple%d is a function that converts its %d parameters into a [Tuple%d]\n", i, i, i)
fmt.Fprintf(f, "func MakeTuple%d[", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j)
}
fmt.Fprintf(f, " any](")
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "t%d T%d", j, j)
}
fmt.Fprintf(f, ") ")
writeTupleType(f, i)
fmt.Fprintf(f, " {\n")
fmt.Fprintf(f, " return Tuple%d[", i)
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j)
}
fmt.Fprintf(f, "]{")
for j := 1; j <= i; j++ {
if j > 1 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "t%d", j)
}
fmt.Fprintf(f, "}\n")
fmt.Fprintf(f, "}\n")
}
func generateUntupled(f *os.File, i int) {
// Create the optionize version
fmt.Fprintf(f, "\n// Untupled%d converts a function with a [Tuple%d] parameter into a function with %d parameters\n// The inverse function is [Tupled%d]\n", i, i, i, i)
fmt.Fprintf(f, "func Untupled%d[F ~func(Tuple%d[", i, i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, "]) R")
for j := 0; j < i; j++ {
fmt.Fprintf(f, ", T%d", j+1)
}
fmt.Fprintf(f, ", R any](f F) func(")
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, ") R {\n")
fmt.Fprintf(f, " return func(")
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "t%d T%d", j+1, j+1)
}
fmt.Fprintf(f, ") R {\n")
fmt.Fprintf(f, " return f(MakeTuple%d(", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "t%d", j+1)
}
fmt.Fprintln(f, "))")
fmt.Fprintln(f, " }")
fmt.Fprintln(f, "}")
}
func generateTupled(f *os.File, i int) {
// Create the optionize version
fmt.Fprintf(f, "\n// Tupled%d converts a function with %d parameters returning into a function taking a Tuple%d\n// The inverse function is [Untupled%d]\n", i, i, i, i)
fmt.Fprintf(f, "func Tupled%d[F ~func(", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, ") R")
for j := 0; j < i; j++ {
fmt.Fprintf(f, ", T%d", j+1)
}
fmt.Fprintf(f, ", R any](f F) func(Tuple%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, "]) R {\n")
fmt.Fprintf(f, " return func(t Tuple%d[", i)
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "T%d", j+1)
}
fmt.Fprintf(f, "]) R {\n")
fmt.Fprintf(f, " return f(")
for j := 0; j < i; j++ {
if j > 0 {
fmt.Fprintf(f, ", ")
}
fmt.Fprintf(f, "t.F%d", j+1)
}
fmt.Fprintf(f, ")\n")
fmt.Fprintf(f, " }\n")
fmt.Fprintln(f, "}")
}
func generateTupleHelpers(filename string, count int) error {
dir, err := os.Getwd()
if err != nil {
return err
}
absDir, err := filepath.Abs(dir)
if err != nil {
return err
}
pkg := filepath.Base(absDir)
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
// log
log.Printf("Generating code in [%s] for package [%s] with [%d] repetitions ...", filename, pkg, count)
// some header
fmt.Fprintln(f, "// Code generated by go generate; DO NOT EDIT.")
fmt.Fprintln(f, "// This file was generated by robots at")
fmt.Fprintf(f, "// %s\n", time.Now())
fmt.Fprintf(f, "package %s\n\n", pkg)
fmt.Fprintf(f, `
import (
M "github.com/ibm/fp-go/monoid"
O "github.com/ibm/fp-go/ord"
)
`)
for i := 1; i <= count; i++ {
// tuple type
generateTupleType(f, i)
}
for i := 1; i <= count; i++ {
// tuple generator
generateMakeTupleType(f, i)
// tupled wrapper
generateTupled(f, i)
// untupled wrapper
generateUntupled(f, i)
// monoid
generateMonoid(f, i)
// generate order
generateOrd(f, i)
}
return nil
}
func TupleCommand() *C.Command {
return &C.Command{
Name: "tuple",
Usage: "generate code for Tuple",
Flags: []C.Flag{
flagCount,
flagFilename,
},
Action: func(ctx *C.Context) error {
return generateTupleHelpers(
ctx.String(keyFilename),
ctx.Int(keyCount),
)
},
}
}

View File

@ -1,180 +1,203 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 16:10:30.7402002 +0200 CEST m=+0.008416101 // 2023-07-13 17:33:41.4844284 +0200 CEST m=+0.009082001
package either package either
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning an 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] { func Eitherize0[F ~func() (R, error), R any](f F) func() Either[error, R] {
return func() Either[error, R] { return func() Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f() return f()
}) })
} }
} }
// Uneitherize0 converts a function with 0 parameters returning an Either into a function with 0 parameters returning a tuple // 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) { func Uneitherize0[F ~func() Either[error, R], R any](f F) func() (R, error) {
return func() (R, error) { return func() (R, error) {
return UnwrapError(f()) return UnwrapError(f())
} }
} }
// Eitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning an Either // 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] { 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 func(t0 T0) Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f(t0) return f(t0)
}) })
} }
} }
// Uneitherize1 converts a function with 1 parameters returning an Either into a function with 1 parameters returning a tuple // 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) { func Uneitherize1[F ~func(T0) Either[error, R], T0, R any](f F) func(T0) (R, error) {
return func(t0 T0) (R, error) { return func(t0 T0) (R, error) {
return UnwrapError(f(t0)) return UnwrapError(f(t0))
} }
} }
// Eitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning an Either // 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] { 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 func(t0 T0, t1 T1) Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f(t0, t1) return f(t0, t1)
}) })
} }
} }
// Uneitherize2 converts a function with 2 parameters returning an Either into a function with 2 parameters returning a tuple // 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) { 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 func(t0 T0, t1 T1) (R, error) {
return UnwrapError(f(t0, t1)) return UnwrapError(f(t0, t1))
} }
} }
// Eitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning an Either // 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] { 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 func(t0 T0, t1 T1, t2 T2) Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f(t0, t1, t2) return f(t0, t1, t2)
}) })
} }
} }
// Uneitherize3 converts a function with 3 parameters returning an Either into a function with 3 parameters returning a tuple // 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) { 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 func(t0 T0, t1 T1, t2 T2) (R, error) {
return UnwrapError(f(t0, t1, t2)) 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 // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3) Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3) 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 // 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) { 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 func(t0 T0, t1 T1, t2 T2, t3 T3) (R, error) {
return UnwrapError(f(t0, t1, t2, t3)) 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 // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4) 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 // 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) { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4)) 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 // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5) 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 // 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) { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) (R, error) {
return UnwrapError(f(t0, t1, t2, t3, t4, t5)) 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 // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) Either[error, R] {
return TryCatchError(func() (R, error) { return TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6) 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 // 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) { 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 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)) 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 // 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] { 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 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 TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7) 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 // 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) { 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 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)) 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 // 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] { 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 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 TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8) 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 // 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) { 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 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)) 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 // 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] { 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 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 TryCatchError(func() (R, error) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) 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 // 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) { 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 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)) return UnwrapError(f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
} }
} }

BIN
fp-go.exe

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2023-07-13 16:10:33.8303184 +0200 CEST m=+0.008901701 // 2023-07-13 17:33:44.6167774 +0200 CEST m=+0.036849901
package option package option
// optionize converts a nullary function to an option // optionize converts a nullary function to an option
@ -13,176 +13,176 @@ func optionize[R any](f func() (R, bool)) Option[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] // 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] { func Optionize0[F ~func() (R, bool), R any](f F) func() Option[R] {
return func() Option[R] { return func() Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f() 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] // 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) { func Unoptionize0[F ~func() Option[R], R any](f F) func() (R, bool) {
return func() (R, bool) { return func() (R, bool) {
return Unwrap(f()) 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] // 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] { func Optionize1[F ~func(T0) (R, bool), T0, R any](f F) func(T0) Option[R] {
return func(t0 T0) Option[R] { return func(t0 T0) Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f(t0) 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] // 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) { func Unoptionize1[F ~func(T0) Option[R], T0, R any](f F) func(T0) (R, bool) {
return func(t0 T0) (R, bool) { return func(t0 T0) (R, bool) {
return Unwrap(f(t0)) 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] // 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] { 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 func(t0 T0, t1 T1) Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f(t0, t1) 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] // 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) { 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 func(t0 T0, t1 T1) (R, bool) {
return Unwrap(f(t0, t1)) 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] // 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] { 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 func(t0 T0, t1 T1, t2 T2) Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f(t0, t1, t2) 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] // 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) { 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 func(t0 T0, t1 T1, t2 T2) (R, bool) {
return Unwrap(f(t0, t1, t2)) 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] // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3) Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f(t0, t1, t2, t3) 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] // 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) { 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 func(t0 T0, t1 T1, t2 T2, t3 T3) (R, bool) {
return Unwrap(f(t0, t1, t2, t3)) 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] // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4) 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] // 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) { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4)) 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] // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5) 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] // 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) { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) (R, bool) {
return Unwrap(f(t0, t1, t2, t3, t4, t5)) 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] // 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] { 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) Option[R] {
return optionize(func() (R, bool) { return optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6) 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] // 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) { 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 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)) 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] // 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] { 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 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 optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7) 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] // 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) { 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 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)) 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] // 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] { 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 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 optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8) 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] // 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) { 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 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)) 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] // 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] { 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 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 optionize(func() (R, bool) {
return f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) 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] // 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) { 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 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)) return Unwrap(f(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
} }
} }

3
tuple/doc.go Normal file
View File

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

530
tuple/gen.go Normal file
View File

@ -0,0 +1,530 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2023-07-13 17:33:46.2312033 +0200 CEST m=+0.009503201
package tuple
import (
M "github.com/ibm/fp-go/monoid"
O "github.com/ibm/fp-go/ord"
)
// Tuple1 is a struct that carries 1 independently typed values
type Tuple1[T1 any] struct {
F1 T1
}
// Tuple2 is a struct that carries 2 independently typed values
type Tuple2[T1, T2 any] struct {
F1 T1
F2 T2
}
// Tuple3 is a struct that carries 3 independently typed values
type Tuple3[T1, T2, T3 any] struct {
F1 T1
F2 T2
F3 T3
}
// Tuple4 is a struct that carries 4 independently typed values
type Tuple4[T1, T2, T3, T4 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
}
// Tuple5 is a struct that carries 5 independently typed values
type Tuple5[T1, T2, T3, T4, T5 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
F5 T5
}
// Tuple6 is a struct that carries 6 independently typed values
type Tuple6[T1, T2, T3, T4, T5, T6 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
F5 T5
F6 T6
}
// Tuple7 is a struct that carries 7 independently typed values
type Tuple7[T1, T2, T3, T4, T5, T6, T7 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
F5 T5
F6 T6
F7 T7
}
// Tuple8 is a struct that carries 8 independently typed values
type Tuple8[T1, T2, T3, T4, T5, T6, T7, T8 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
F5 T5
F6 T6
F7 T7
F8 T8
}
// Tuple9 is a struct that carries 9 independently typed values
type Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
F5 T5
F6 T6
F7 T7
F8 T8
F9 T9
}
// Tuple10 is a struct that carries 10 independently typed values
type Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
F5 T5
F6 T6
F7 T7
F8 T8
F9 T9
F10 T10
}
// MakeTuple1 is a function that converts its 1 parameters into a [Tuple1]
func MakeTuple1[T1 any](t1 T1) Tuple1[T1] {
return Tuple1[T1]{t1}
}
// Tupled1 converts a function with 1 parameters returning into a function taking a Tuple1
// The inverse function is [Untupled1]
func Tupled1[F ~func(T1) R, T1, R any](f F) func(Tuple1[T1]) R {
return func(t Tuple1[T1]) R {
return f(t.F1)
}
}
// Untupled1 converts a function with a [Tuple1] parameter into a function with 1 parameters
// The inverse function is [Tupled1]
func Untupled1[F ~func(Tuple1[T1]) R, T1, R any](f F) func(T1) R {
return func(t1 T1) R {
return f(MakeTuple1(t1))
}
}
// Monoid1 creates a [Monoid] for a [Tuple1] based on 1 monoids for the contained types
func Monoid1[T1 any](m1 M.Monoid[T1]) M.Monoid[Tuple1[T1]] {
return M.MakeMonoid(func(l, r Tuple1[T1]) Tuple1[T1]{
return MakeTuple1(m1.Concat(l.F1, r.F1))
}, MakeTuple1(m1.Empty()))
}
// Ord1 creates n [Ord] for a [Tuple1] based on 1 [Ord]s for the contained types
func Ord1[T1 any](o1 O.Ord[T1]) O.Ord[Tuple1[T1]] {
return O.MakeOrd(func(l, r Tuple1[T1]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
return 0
}, func(l, r Tuple1[T1]) bool {
return o1.Equals(l.F1, r.F1)
})
}
// MakeTuple2 is a function that converts its 2 parameters into a [Tuple2]
func MakeTuple2[T1, T2 any](t1 T1, t2 T2) Tuple2[T1, T2] {
return Tuple2[T1, T2]{t1, t2}
}
// Tupled2 converts a function with 2 parameters returning into a function taking a Tuple2
// The inverse function is [Untupled2]
func Tupled2[F ~func(T1, T2) R, T1, T2, R any](f F) func(Tuple2[T1, T2]) R {
return func(t Tuple2[T1, T2]) R {
return f(t.F1, t.F2)
}
}
// Untupled2 converts a function with a [Tuple2] parameter into a function with 2 parameters
// The inverse function is [Tupled2]
func Untupled2[F ~func(Tuple2[T1, T2]) R, T1, T2, R any](f F) func(T1, T2) R {
return func(t1 T1, t2 T2) R {
return f(MakeTuple2(t1, t2))
}
}
// Monoid2 creates a [Monoid] for a [Tuple2] based on 2 monoids for the contained types
func Monoid2[T1, T2 any](m1 M.Monoid[T1], m2 M.Monoid[T2]) M.Monoid[Tuple2[T1, T2]] {
return M.MakeMonoid(func(l, r Tuple2[T1, T2]) Tuple2[T1, T2]{
return MakeTuple2(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2))
}, MakeTuple2(m1.Empty(), m2.Empty()))
}
// Ord2 creates n [Ord] for a [Tuple2] based on 2 [Ord]s for the contained types
func Ord2[T1, T2 any](o1 O.Ord[T1], o2 O.Ord[T2]) O.Ord[Tuple2[T1, T2]] {
return O.MakeOrd(func(l, r Tuple2[T1, T2]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
return 0
}, func(l, r Tuple2[T1, T2]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2)
})
}
// MakeTuple3 is a function that converts its 3 parameters into a [Tuple3]
func MakeTuple3[T1, T2, T3 any](t1 T1, t2 T2, t3 T3) Tuple3[T1, T2, T3] {
return Tuple3[T1, T2, T3]{t1, t2, t3}
}
// Tupled3 converts a function with 3 parameters returning into a function taking a Tuple3
// The inverse function is [Untupled3]
func Tupled3[F ~func(T1, T2, T3) R, T1, T2, T3, R any](f F) func(Tuple3[T1, T2, T3]) R {
return func(t Tuple3[T1, T2, T3]) R {
return f(t.F1, t.F2, t.F3)
}
}
// Untupled3 converts a function with a [Tuple3] parameter into a function with 3 parameters
// The inverse function is [Tupled3]
func Untupled3[F ~func(Tuple3[T1, T2, T3]) R, T1, T2, T3, R any](f F) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R {
return f(MakeTuple3(t1, t2, t3))
}
}
// Monoid3 creates a [Monoid] for a [Tuple3] based on 3 monoids for the contained types
func Monoid3[T1, T2, T3 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3]) M.Monoid[Tuple3[T1, T2, T3]] {
return M.MakeMonoid(func(l, r Tuple3[T1, T2, T3]) Tuple3[T1, T2, T3]{
return MakeTuple3(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3))
}, MakeTuple3(m1.Empty(), m2.Empty(), m3.Empty()))
}
// Ord3 creates n [Ord] for a [Tuple3] based on 3 [Ord]s for the contained types
func Ord3[T1, T2, T3 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3]) O.Ord[Tuple3[T1, T2, T3]] {
return O.MakeOrd(func(l, r Tuple3[T1, T2, T3]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
return 0
}, func(l, r Tuple3[T1, T2, T3]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3)
})
}
// MakeTuple4 is a function that converts its 4 parameters into a [Tuple4]
func MakeTuple4[T1, T2, T3, T4 any](t1 T1, t2 T2, t3 T3, t4 T4) Tuple4[T1, T2, T3, T4] {
return Tuple4[T1, T2, T3, T4]{t1, t2, t3, t4}
}
// Tupled4 converts a function with 4 parameters returning into a function taking a Tuple4
// The inverse function is [Untupled4]
func Tupled4[F ~func(T1, T2, T3, T4) R, T1, T2, T3, T4, R any](f F) func(Tuple4[T1, T2, T3, T4]) R {
return func(t Tuple4[T1, T2, T3, T4]) R {
return f(t.F1, t.F2, t.F3, t.F4)
}
}
// Untupled4 converts a function with a [Tuple4] parameter into a function with 4 parameters
// The inverse function is [Tupled4]
func Untupled4[F ~func(Tuple4[T1, T2, T3, T4]) R, T1, 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 f(MakeTuple4(t1, t2, t3, t4))
}
}
// Monoid4 creates a [Monoid] for a [Tuple4] based on 4 monoids for the contained types
func Monoid4[T1, T2, T3, T4 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4]) M.Monoid[Tuple4[T1, T2, T3, T4]] {
return M.MakeMonoid(func(l, r Tuple4[T1, T2, T3, T4]) Tuple4[T1, T2, T3, T4]{
return MakeTuple4(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3), m4.Concat(l.F4, r.F4))
}, MakeTuple4(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty()))
}
// Ord4 creates n [Ord] for a [Tuple4] based on 4 [Ord]s for the contained types
func Ord4[T1, T2, T3, T4 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4]) O.Ord[Tuple4[T1, T2, T3, T4]] {
return O.MakeOrd(func(l, r Tuple4[T1, T2, T3, T4]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
if c:= o4.Compare(l.F4, r.F4); c != 0 {return c}
return 0
}, func(l, r Tuple4[T1, T2, T3, T4]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4)
})
}
// MakeTuple5 is a function that converts its 5 parameters into a [Tuple5]
func MakeTuple5[T1, T2, T3, T4, T5 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) Tuple5[T1, T2, T3, T4, T5] {
return Tuple5[T1, T2, T3, T4, T5]{t1, t2, t3, t4, t5}
}
// Tupled5 converts a function with 5 parameters returning into a function taking a Tuple5
// The inverse function is [Untupled5]
func Tupled5[F ~func(T1, T2, T3, T4, T5) R, T1, T2, T3, T4, T5, R any](f F) func(Tuple5[T1, T2, T3, T4, T5]) R {
return func(t Tuple5[T1, T2, T3, T4, T5]) R {
return f(t.F1, t.F2, t.F3, t.F4, t.F5)
}
}
// Untupled5 converts a function with a [Tuple5] parameter into a function with 5 parameters
// The inverse function is [Tupled5]
func Untupled5[F ~func(Tuple5[T1, T2, T3, T4, T5]) R, T1, T2, T3, T4, T5, R any](f F) func(T1, T2, T3, T4, T5) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) R {
return f(MakeTuple5(t1, t2, t3, t4, t5))
}
}
// Monoid5 creates a [Monoid] for a [Tuple5] based on 5 monoids for the contained types
func Monoid5[T1, T2, T3, T4, T5 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4], m5 M.Monoid[T5]) M.Monoid[Tuple5[T1, T2, T3, T4, T5]] {
return M.MakeMonoid(func(l, r Tuple5[T1, T2, T3, T4, T5]) Tuple5[T1, T2, T3, T4, T5]{
return MakeTuple5(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3), m4.Concat(l.F4, r.F4), m5.Concat(l.F5, r.F5))
}, MakeTuple5(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty(), m5.Empty()))
}
// Ord5 creates n [Ord] for a [Tuple5] based on 5 [Ord]s for the contained types
func Ord5[T1, T2, T3, T4, T5 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4], o5 O.Ord[T5]) O.Ord[Tuple5[T1, T2, T3, T4, T5]] {
return O.MakeOrd(func(l, r Tuple5[T1, T2, T3, T4, T5]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
if c:= o4.Compare(l.F4, r.F4); c != 0 {return c}
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
return 0
}, func(l, r Tuple5[T1, T2, T3, T4, T5]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4) && o5.Equals(l.F5, r.F5)
})
}
// MakeTuple6 is a function that converts its 6 parameters into a [Tuple6]
func MakeTuple6[T1, T2, T3, T4, T5, T6 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) Tuple6[T1, T2, T3, T4, T5, T6] {
return Tuple6[T1, T2, T3, T4, T5, T6]{t1, t2, t3, t4, t5, t6}
}
// Tupled6 converts a function with 6 parameters returning into a function taking a Tuple6
// The inverse function is [Untupled6]
func Tupled6[F ~func(T1, T2, T3, T4, T5, T6) R, T1, T2, T3, T4, T5, T6, R any](f F) func(Tuple6[T1, T2, T3, T4, T5, T6]) R {
return func(t Tuple6[T1, T2, T3, T4, T5, T6]) R {
return f(t.F1, t.F2, t.F3, t.F4, t.F5, t.F6)
}
}
// Untupled6 converts a function with a [Tuple6] parameter into a function with 6 parameters
// The inverse function is [Tupled6]
func Untupled6[F ~func(Tuple6[T1, T2, T3, T4, T5, T6]) R, T1, T2, T3, T4, T5, T6, R any](f F) func(T1, T2, T3, T4, T5, T6) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) R {
return f(MakeTuple6(t1, t2, t3, t4, t5, t6))
}
}
// Monoid6 creates a [Monoid] for a [Tuple6] based on 6 monoids for the contained types
func Monoid6[T1, T2, T3, T4, T5, T6 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4], m5 M.Monoid[T5], m6 M.Monoid[T6]) M.Monoid[Tuple6[T1, T2, T3, T4, T5, T6]] {
return M.MakeMonoid(func(l, r Tuple6[T1, T2, T3, T4, T5, T6]) Tuple6[T1, T2, T3, T4, T5, T6]{
return MakeTuple6(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3), m4.Concat(l.F4, r.F4), m5.Concat(l.F5, r.F5), m6.Concat(l.F6, r.F6))
}, MakeTuple6(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty(), m5.Empty(), m6.Empty()))
}
// Ord6 creates n [Ord] for a [Tuple6] based on 6 [Ord]s for the contained types
func Ord6[T1, T2, T3, T4, T5, T6 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4], o5 O.Ord[T5], o6 O.Ord[T6]) O.Ord[Tuple6[T1, T2, T3, T4, T5, T6]] {
return O.MakeOrd(func(l, r Tuple6[T1, T2, T3, T4, T5, T6]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
if c:= o4.Compare(l.F4, r.F4); c != 0 {return c}
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
if c:= o6.Compare(l.F6, r.F6); c != 0 {return c}
return 0
}, func(l, r Tuple6[T1, T2, T3, T4, T5, T6]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4) && o5.Equals(l.F5, r.F5) && o6.Equals(l.F6, r.F6)
})
}
// MakeTuple7 is a function that converts its 7 parameters into a [Tuple7]
func MakeTuple7[T1, T2, T3, T4, T5, T6, T7 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) Tuple7[T1, T2, T3, T4, T5, T6, T7] {
return Tuple7[T1, T2, T3, T4, T5, T6, T7]{t1, t2, t3, t4, t5, t6, t7}
}
// Tupled7 converts a function with 7 parameters returning into a function taking a Tuple7
// The inverse function is [Untupled7]
func Tupled7[F ~func(T1, T2, T3, T4, T5, T6, T7) R, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(Tuple7[T1, T2, T3, T4, T5, T6, T7]) R {
return func(t Tuple7[T1, T2, T3, T4, T5, T6, T7]) R {
return f(t.F1, t.F2, t.F3, t.F4, t.F5, t.F6, t.F7)
}
}
// Untupled7 converts a function with a [Tuple7] parameter into a function with 7 parameters
// The inverse function is [Tupled7]
func Untupled7[F ~func(Tuple7[T1, T2, T3, T4, T5, T6, T7]) R, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T1, T2, T3, T4, T5, T6, T7) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) R {
return f(MakeTuple7(t1, t2, t3, t4, t5, t6, t7))
}
}
// Monoid7 creates a [Monoid] for a [Tuple7] based on 7 monoids for the contained types
func Monoid7[T1, T2, T3, T4, T5, T6, T7 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4], m5 M.Monoid[T5], m6 M.Monoid[T6], m7 M.Monoid[T7]) M.Monoid[Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return M.MakeMonoid(func(l, r Tuple7[T1, T2, T3, T4, T5, T6, T7]) Tuple7[T1, T2, T3, T4, T5, T6, T7]{
return MakeTuple7(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3), m4.Concat(l.F4, r.F4), m5.Concat(l.F5, r.F5), m6.Concat(l.F6, r.F6), m7.Concat(l.F7, r.F7))
}, MakeTuple7(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty(), m5.Empty(), m6.Empty(), m7.Empty()))
}
// Ord7 creates n [Ord] for a [Tuple7] based on 7 [Ord]s for the contained types
func Ord7[T1, T2, T3, T4, T5, T6, T7 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4], o5 O.Ord[T5], o6 O.Ord[T6], o7 O.Ord[T7]) O.Ord[Tuple7[T1, T2, T3, T4, T5, T6, T7]] {
return O.MakeOrd(func(l, r Tuple7[T1, T2, T3, T4, T5, T6, T7]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
if c:= o4.Compare(l.F4, r.F4); c != 0 {return c}
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
if c:= o6.Compare(l.F6, r.F6); c != 0 {return c}
if c:= o7.Compare(l.F7, r.F7); c != 0 {return c}
return 0
}, func(l, r Tuple7[T1, T2, T3, T4, T5, T6, T7]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4) && o5.Equals(l.F5, r.F5) && o6.Equals(l.F6, r.F6) && o7.Equals(l.F7, r.F7)
})
}
// MakeTuple8 is a function that converts its 8 parameters into a [Tuple8]
func MakeTuple8[T1, T2, T3, T4, T5, T6, T7, T8 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) Tuple8[T1, T2, T3, T4, T5, T6, T7, T8] {
return Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]{t1, t2, t3, t4, t5, t6, t7, t8}
}
// Tupled8 converts a function with 8 parameters returning into a function taking a Tuple8
// The inverse function is [Untupled8]
func Tupled8[F ~func(T1, T2, T3, T4, T5, T6, T7, T8) R, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) R {
return func(t Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) R {
return f(t.F1, t.F2, t.F3, t.F4, t.F5, t.F6, t.F7, t.F8)
}
}
// Untupled8 converts a function with a [Tuple8] parameter into a function with 8 parameters
// The inverse function is [Tupled8]
func Untupled8[F ~func(Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) R, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T1, T2, T3, T4, T5, T6, T7, T8) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) R {
return f(MakeTuple8(t1, t2, t3, t4, t5, t6, t7, t8))
}
}
// Monoid8 creates a [Monoid] for a [Tuple8] based on 8 monoids for the contained types
func Monoid8[T1, T2, T3, T4, T5, T6, T7, T8 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4], m5 M.Monoid[T5], m6 M.Monoid[T6], m7 M.Monoid[T7], m8 M.Monoid[T8]) M.Monoid[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return M.MakeMonoid(func(l, r Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]{
return MakeTuple8(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3), m4.Concat(l.F4, r.F4), m5.Concat(l.F5, r.F5), m6.Concat(l.F6, r.F6), m7.Concat(l.F7, r.F7), m8.Concat(l.F8, r.F8))
}, MakeTuple8(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty(), m5.Empty(), m6.Empty(), m7.Empty(), m8.Empty()))
}
// Ord8 creates n [Ord] for a [Tuple8] based on 8 [Ord]s for the contained types
func Ord8[T1, T2, T3, T4, T5, T6, T7, T8 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4], o5 O.Ord[T5], o6 O.Ord[T6], o7 O.Ord[T7], o8 O.Ord[T8]) O.Ord[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] {
return O.MakeOrd(func(l, r Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
if c:= o4.Compare(l.F4, r.F4); c != 0 {return c}
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
if c:= o6.Compare(l.F6, r.F6); c != 0 {return c}
if c:= o7.Compare(l.F7, r.F7); c != 0 {return c}
if c:= o8.Compare(l.F8, r.F8); c != 0 {return c}
return 0
}, func(l, r Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4) && o5.Equals(l.F5, r.F5) && o6.Equals(l.F6, r.F6) && o7.Equals(l.F7, r.F7) && o8.Equals(l.F8, r.F8)
})
}
// MakeTuple9 is a function that converts its 9 parameters into a [Tuple9]
func MakeTuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9] {
return Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]{t1, t2, t3, t4, t5, t6, t7, t8, t9}
}
// Tupled9 converts a function with 9 parameters returning into a function taking a Tuple9
// The inverse function is [Untupled9]
func Tupled9[F ~func(T1, T2, T3, T4, T5, T6, T7, T8, T9) R, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) R {
return func(t Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) R {
return f(t.F1, t.F2, t.F3, t.F4, t.F5, t.F6, t.F7, t.F8, t.F9)
}
}
// Untupled9 converts a function with a [Tuple9] parameter into a function with 9 parameters
// The inverse function is [Tupled9]
func Untupled9[F ~func(Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) R, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T1, T2, T3, T4, T5, T6, T7, T8, T9) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) R {
return f(MakeTuple9(t1, t2, t3, t4, t5, t6, t7, t8, t9))
}
}
// Monoid9 creates a [Monoid] for a [Tuple9] based on 9 monoids for the contained types
func Monoid9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4], m5 M.Monoid[T5], m6 M.Monoid[T6], m7 M.Monoid[T7], m8 M.Monoid[T8], m9 M.Monoid[T9]) M.Monoid[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return M.MakeMonoid(func(l, r Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]{
return MakeTuple9(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3), m4.Concat(l.F4, r.F4), m5.Concat(l.F5, r.F5), m6.Concat(l.F6, r.F6), m7.Concat(l.F7, r.F7), m8.Concat(l.F8, r.F8), m9.Concat(l.F9, r.F9))
}, MakeTuple9(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty(), m5.Empty(), m6.Empty(), m7.Empty(), m8.Empty(), m9.Empty()))
}
// Ord9 creates n [Ord] for a [Tuple9] based on 9 [Ord]s for the contained types
func Ord9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4], o5 O.Ord[T5], o6 O.Ord[T6], o7 O.Ord[T7], o8 O.Ord[T8], o9 O.Ord[T9]) O.Ord[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] {
return O.MakeOrd(func(l, r Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
if c:= o4.Compare(l.F4, r.F4); c != 0 {return c}
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
if c:= o6.Compare(l.F6, r.F6); c != 0 {return c}
if c:= o7.Compare(l.F7, r.F7); c != 0 {return c}
if c:= o8.Compare(l.F8, r.F8); c != 0 {return c}
if c:= o9.Compare(l.F9, r.F9); c != 0 {return c}
return 0
}, func(l, r Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4) && o5.Equals(l.F5, r.F5) && o6.Equals(l.F6, r.F6) && o7.Equals(l.F7, r.F7) && o8.Equals(l.F8, r.F8) && o9.Equals(l.F9, r.F9)
})
}
// MakeTuple10 is a function that converts its 10 parameters into a [Tuple10]
func MakeTuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10) Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10] {
return Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]{t1, t2, t3, t4, t5, t6, t7, t8, t9, t10}
}
// Tupled10 converts a function with 10 parameters returning into a function taking a Tuple10
// The inverse function is [Untupled10]
func Tupled10[F ~func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](f F) func(Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) R {
return func(t Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) R {
return f(t.F1, t.F2, t.F3, t.F4, t.F5, t.F6, t.F7, t.F8, t.F9, t.F10)
}
}
// Untupled10 converts a function with a [Tuple10] parameter into a function with 10 parameters
// The inverse function is [Tupled10]
func Untupled10[F ~func(Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) R, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](f F) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) R {
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10) R {
return f(MakeTuple10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10))
}
}
// Monoid10 creates a [Monoid] for a [Tuple10] based on 10 monoids for the contained types
func Monoid10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4], m5 M.Monoid[T5], m6 M.Monoid[T6], m7 M.Monoid[T7], m8 M.Monoid[T8], m9 M.Monoid[T9], m10 M.Monoid[T10]) M.Monoid[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return M.MakeMonoid(func(l, r Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]{
return MakeTuple10(m1.Concat(l.F1, r.F1), m2.Concat(l.F2, r.F2), m3.Concat(l.F3, r.F3), m4.Concat(l.F4, r.F4), m5.Concat(l.F5, r.F5), m6.Concat(l.F6, r.F6), m7.Concat(l.F7, r.F7), m8.Concat(l.F8, r.F8), m9.Concat(l.F9, r.F9), m10.Concat(l.F10, r.F10))
}, MakeTuple10(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty(), m5.Empty(), m6.Empty(), m7.Empty(), m8.Empty(), m9.Empty(), m10.Empty()))
}
// Ord10 creates n [Ord] for a [Tuple10] based on 10 [Ord]s for the contained types
func Ord10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4], o5 O.Ord[T5], o6 O.Ord[T6], o7 O.Ord[T7], o8 O.Ord[T8], o9 O.Ord[T9], o10 O.Ord[T10]) O.Ord[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] {
return O.MakeOrd(func(l, r Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) int {
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
if c:= o3.Compare(l.F3, r.F3); c != 0 {return c}
if c:= o4.Compare(l.F4, r.F4); c != 0 {return c}
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
if c:= o6.Compare(l.F6, r.F6); c != 0 {return c}
if c:= o7.Compare(l.F7, r.F7); c != 0 {return c}
if c:= o8.Compare(l.F8, r.F8); c != 0 {return c}
if c:= o9.Compare(l.F9, r.F9); c != 0 {return c}
if c:= o10.Compare(l.F10, r.F10); c != 0 {return c}
return 0
}, func(l, r Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4) && o5.Equals(l.F5, r.F5) && o6.Equals(l.F6, r.F6) && o7.Equals(l.F7, r.F7) && o8.Equals(l.F8, r.F8) && o9.Equals(l.F9, r.F9) && o10.Equals(l.F10, r.F10)
})
}

View File

@ -1,33 +0,0 @@
package tuple
import (
M "github.com/ibm/fp-go/monoid"
)
// Monoid1 implements a monoid for a 1-tuple
func Monoid1[T1 any](m1 M.Monoid[T1]) M.Monoid[Tuple1[T1]] {
return M.MakeMonoid(func(l, r Tuple1[T1]) Tuple1[T1] {
return MakeTuple1(m1.Concat(l.F1, l.F1))
}, MakeTuple1(m1.Empty()))
}
// Monoid2 implements a monoid for a 2-tuple
func Monoid2[T1, T2 any](m1 M.Monoid[T1], m2 M.Monoid[T2]) M.Monoid[Tuple2[T1, T2]] {
return M.MakeMonoid(func(l, r Tuple2[T1, T2]) Tuple2[T1, T2] {
return MakeTuple2(m1.Concat(l.F1, l.F1), m2.Concat(l.F2, l.F2))
}, MakeTuple2(m1.Empty(), m2.Empty()))
}
// Monoid3 implements a monoid for a 3-tuple
func Monoid3[T1, T2, T3 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3]) M.Monoid[Tuple3[T1, T2, T3]] {
return M.MakeMonoid(func(l, r Tuple3[T1, T2, T3]) Tuple3[T1, T2, T3] {
return MakeTuple3(m1.Concat(l.F1, l.F1), m2.Concat(l.F2, l.F2), m3.Concat(l.F3, l.F3))
}, MakeTuple3(m1.Empty(), m2.Empty(), m3.Empty()))
}
// Monoid4 implements a monoid for a 4-tuple
func Monoid4[T1, T2, T3, T4 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3], m4 M.Monoid[T4]) M.Monoid[Tuple4[T1, T2, T3, T4]] {
return M.MakeMonoid(func(l, r Tuple4[T1, T2, T3, T4]) Tuple4[T1, T2, T3, T4] {
return MakeTuple4(m1.Concat(l.F1, l.F1), m2.Concat(l.F2, l.F2), m3.Concat(l.F3, l.F3), m4.Concat(l.F4, l.F4))
}, MakeTuple4(m1.Empty(), m2.Empty(), m3.Empty(), m4.Empty()))
}

View File

@ -1,68 +0,0 @@
package tuple
import (
O "github.com/ibm/fp-go/ord"
)
// Ord1 implements ordering on a 1-tuple
func Ord1[T1 any](o1 O.Ord[T1]) O.Ord[Tuple1[T1]] {
return O.MakeOrd(func(l, r Tuple1[T1]) int {
return o1.Compare(l.F1, r.F1)
}, func(l, r Tuple1[T1]) bool {
return o1.Equals(l.F1, r.F1)
})
}
// Ord2 implements ordering on a 2-tuple
func Ord2[T1, T2 any](o1 O.Ord[T1], o2 O.Ord[T2]) O.Ord[Tuple2[T1, T2]] {
return O.MakeOrd(func(l, r Tuple2[T1, T2]) int {
c := o1.Compare(l.F1, r.F1)
if c != 0 {
return c
}
c = o2.Compare(l.F2, r.F2)
return c
}, func(l, r Tuple2[T1, T2]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2)
})
}
// Ord3 implements ordering on a 3-tuple
func Ord3[T1, T2, T3 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3]) O.Ord[Tuple3[T1, T2, T3]] {
return O.MakeOrd(func(l, r Tuple3[T1, T2, T3]) int {
c := o1.Compare(l.F1, r.F1)
if c != 0 {
return c
}
c = o2.Compare(l.F2, r.F2)
if c != 0 {
return c
}
c = o3.Compare(l.F3, r.F3)
return c
}, func(l, r Tuple3[T1, T2, T3]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3)
})
}
// Ord4 implements ordering on a 4-tuple
func Ord4[T1, T2, T3, T4 any](o1 O.Ord[T1], o2 O.Ord[T2], o3 O.Ord[T3], o4 O.Ord[T4]) O.Ord[Tuple4[T1, T2, T3, T4]] {
return O.MakeOrd(func(l, r Tuple4[T1, T2, T3, T4]) int {
c := o1.Compare(l.F1, r.F1)
if c != 0 {
return c
}
c = o2.Compare(l.F2, r.F2)
if c != 0 {
return c
}
c = o3.Compare(l.F3, r.F3)
if c != 0 {
return c
}
c = o4.Compare(l.F4, r.F4)
return c
}, func(l, r Tuple4[T1, T2, T3, T4]) bool {
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3) && o4.Equals(l.F4, r.F4)
})
}

View File

@ -2,76 +2,6 @@
// consider to use arrays for simplicity // consider to use arrays for simplicity
package tuple package tuple
// Tuple1 is a structure carrying one element
type Tuple1[T1 any] struct {
F1 T1
}
// Tuple2 is a structure carrying two elements
type Tuple2[T1, T2 any] struct {
F1 T1
F2 T2
}
// Tuple3 is a structure carrying three elements
type Tuple3[T1, T2, T3 any] struct {
F1 T1
F2 T2
F3 T3
}
// Tuple4 is a structure carrying four elements
type Tuple4[T1, T2, T3, T4 any] struct {
F1 T1
F2 T2
F3 T3
F4 T4
}
func MakeTuple1[T1 any](t1 T1) Tuple1[T1] {
return Tuple1[T1]{F1: t1}
}
func MakeTuple2[T1, T2 any](t1 T1, t2 T2) Tuple2[T1, T2] {
return Tuple2[T1, T2]{F1: t1, F2: t2}
}
func MakeTuple3[T1, T2, T3 any](t1 T1, t2 T2, t3 T3) Tuple3[T1, T2, T3] {
return Tuple3[T1, T2, T3]{F1: t1, F2: t2, F3: t3}
}
func MakeTuple4[T1, T2, T3, T4 any](t1 T1, t2 T2, t3 T3, t4 T4) Tuple4[T1, T2, T3, T4] {
return Tuple4[T1, T2, T3, T4]{F1: t1, F2: t2, F3: t3, F4: t4}
}
// Tupled2 converts a function that accepts two parameters into a function that accepts a tuple
func Tupled2[T1, T2, R any](f func(t1 T1, t2 T2) R) func(Tuple2[T1, T2]) R {
return func(t Tuple2[T1, T2]) R {
return f(t.F1, t.F2)
}
}
// Tupled3 converts a function that accepts three parameters into a function that accepts a tuple
func Tupled3[T1, T2, T3, R any](f func(t1 T1, t2 T2, t3 T3) R) func(Tuple3[T1, T2, T3]) R {
return func(t Tuple3[T1, T2, T3]) R {
return f(t.F1, t.F2, t.F3)
}
}
// Untupled2 converts a function that accepts a tuple into a function that accepts two parameters
func Untupled2[T1, T2, R any](f func(Tuple2[T1, T2]) R) func(T1, T2) R {
return func(t1 T1, t2 T2) R {
return f(MakeTuple2(t1, t2))
}
}
// Untupled3 converts a function that accepts a tuple into a function that accepts three parameters
func Untupled3[T1, T2, T3, R any](f func(Tuple3[T1, T2, T3]) R) func(T1, T2, T3) R {
return func(t1 T1, t2 T2, t3 T3) R {
return f(MakeTuple3(t1, t2, t3))
}
}
func First[T1, T2 any](t Tuple2[T1, T2]) T1 { func First[T1, T2 any](t Tuple2[T1, T2]) T1 {
return t.F1 return t.F1
} }