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:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
fp-go.exe
|
@ -9,5 +9,6 @@ func Commands() []*C.Command {
|
||||
PipeCommand(),
|
||||
OptionCommand(),
|
||||
EitherCommand(),
|
||||
TupleCommand(),
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func generateUneitherize(f *os.File, i int) {
|
||||
// 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)
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
@ -54,7 +54,7 @@ func generateUneitherize(f *os.File, i int) {
|
||||
|
||||
func generateEitherize(f *os.File, i int) {
|
||||
// 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)
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
|
323
cli/tuple.go
Normal file
323
cli/tuple.go
Normal 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),
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 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
|
||||
|
||||
|
||||
// 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) {
|
||||
@ -13,6 +15,7 @@ func Eitherize0[F ~func() (R, error), R any](f F) func() Either[error, R] {
|
||||
}
|
||||
|
||||
// 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())
|
||||
@ -20,6 +23,7 @@ func Uneitherize0[F ~func() Either[error, R], R any](f F) func() (R, error) {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -29,6 +33,7 @@ func Eitherize1[F ~func(T0) (R, error), T0, R any](f F) func(T0) Either[error, R
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -36,6 +41,7 @@ func Uneitherize1[F ~func(T0) Either[error, R], T0, R any](f F) func(T0) (R, err
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -45,6 +51,7 @@ func Eitherize2[F ~func(T0, T1) (R, error), T0, T1, R any](f F) func(T0, T1) Eit
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -52,6 +59,7 @@ func Uneitherize2[F ~func(T0, T1) Either[error, R], T0, T1, R any](f F) func(T0,
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -61,6 +69,7 @@ func Eitherize3[F ~func(T0, T1, T2) (R, error), T0, T1, T2, R any](f F) func(T0,
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -68,6 +77,7 @@ func Uneitherize3[F ~func(T0, T1, T2) Either[error, R], T0, T1, T2, R any](f F)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -77,6 +87,7 @@ func Eitherize4[F ~func(T0, T1, T2, T3) (R, error), T0, T1, T2, T3, R any](f F)
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -84,6 +95,7 @@ func Uneitherize4[F ~func(T0, T1, T2, T3) Either[error, R], T0, T1, T2, T3, R an
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -93,6 +105,7 @@ func Eitherize5[F ~func(T0, T1, T2, T3, T4) (R, error), T0, T1, T2, T3, T4, R an
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -100,6 +113,7 @@ func Uneitherize5[F ~func(T0, T1, T2, T3, T4) Either[error, R], T0, T1, T2, T3,
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -109,6 +123,7 @@ func Eitherize6[F ~func(T0, T1, T2, T3, T4, T5) (R, error), T0, T1, T2, T3, T4,
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -116,6 +131,7 @@ func Uneitherize6[F ~func(T0, T1, T2, T3, T4, T5) Either[error, R], T0, T1, T2,
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -125,6 +141,7 @@ func Eitherize7[F ~func(T0, T1, T2, T3, T4, T5, T6) (R, error), T0, T1, T2, T3,
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -132,6 +149,7 @@ func Uneitherize7[F ~func(T0, T1, T2, T3, T4, T5, T6) Either[error, R], T0, T1,
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -141,6 +159,7 @@ func Eitherize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) (R, error), T0, T1, T2,
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -148,6 +167,7 @@ func Uneitherize8[F ~func(T0, T1, T2, T3, T4, T5, T6, T7) Either[error, R], T0,
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -157,6 +177,7 @@ func Eitherize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error), T0, T1,
|
||||
}
|
||||
|
||||
// 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))
|
||||
@ -164,6 +185,7 @@ func Uneitherize9[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8) Either[error, R],
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@ -173,6 +195,7 @@ func Eitherize10[F ~func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error), T0,
|
||||
}
|
||||
|
||||
// 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))
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-13 16:11:39.4638087 +0200 CEST m=+0.008945901
|
||||
// 2023-07-13 17:33:43.0032761 +0200 CEST m=+0.009251401
|
||||
package function
|
||||
|
||||
// Pipe0 takes an initial value t0 and successively applies 0 functions where the input of a function is the return value of the previous function
|
||||
@ -15,14 +15,12 @@ func Variadic0[V, R any](f func([]V) R) func(...V) R {
|
||||
return f(v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic0 converts a function taking 0 parameters and a final variadic argument into a function with 0 parameters but a final slice argument
|
||||
func Unvariadic0[V, R any](f func(...V) R) func([]V) R {
|
||||
return func(v []V) R {
|
||||
return f(v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe1 takes an initial value t0 and successively applies 1 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe1[F1 ~func(T0) T1, T0, T1 any](t0 T0, f1 F1) T1 {
|
||||
@ -67,14 +65,12 @@ func Variadic1[T1, V, R any](f func(T1, []V) R) func(T1, ...V) R {
|
||||
return f(t1, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic1 converts a function taking 1 parameters and a final variadic argument into a function with 1 parameters but a final slice argument
|
||||
func Unvariadic1[T1, V, R any](f func(T1, ...V) R) func(T1, []V) R {
|
||||
return func(t1 T1, v []V) R {
|
||||
return f(t1, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe2 takes an initial value t0 and successively applies 2 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe2[F1 ~func(T0) T1, F2 ~func(T1) T2, T0, T1, T2 any](t0 T0, f1 F1, f2 F2) T2 {
|
||||
@ -122,14 +118,12 @@ func Variadic2[T1, T2, V, R any](f func(T1, T2, []V) R) func(T1, T2, ...V) R {
|
||||
return f(t1, t2, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic2 converts a function taking 2 parameters and a final variadic argument into a function with 2 parameters but a final slice argument
|
||||
func Unvariadic2[T1, T2, V, R any](f func(T1, T2, ...V) R) func(T1, T2, []V) R {
|
||||
return func(t1 T1, t2 T2, v []V) R {
|
||||
return f(t1, t2, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe3 takes an initial value t0 and successively applies 3 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe3[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, T0, T1, T2, T3 any](t0 T0, f1 F1, f2 F2, f3 F3) T3 {
|
||||
@ -180,14 +174,12 @@ func Variadic3[T1, T2, T3, V, R any](f func(T1, T2, T3, []V) R) func(T1, T2, T3,
|
||||
return f(t1, t2, t3, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic3 converts a function taking 3 parameters and a final variadic argument into a function with 3 parameters but a final slice argument
|
||||
func Unvariadic3[T1, T2, T3, V, R any](f func(T1, T2, T3, ...V) R) func(T1, T2, T3, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, v []V) R {
|
||||
return f(t1, t2, t3, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe4 takes an initial value t0 and successively applies 4 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe4[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, T0, T1, T2, T3, T4 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4) T4 {
|
||||
@ -241,14 +233,12 @@ func Variadic4[T1, T2, T3, T4, V, R any](f func(T1, T2, T3, T4, []V) R) func(T1,
|
||||
return f(t1, t2, t3, t4, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic4 converts a function taking 4 parameters and a final variadic argument into a function with 4 parameters but a final slice argument
|
||||
func Unvariadic4[T1, T2, T3, T4, V, R any](f func(T1, T2, T3, T4, ...V) R) func(T1, T2, T3, T4, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, v []V) R {
|
||||
return f(t1, t2, t3, t4, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe5 takes an initial value t0 and successively applies 5 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe5[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, T0, T1, T2, T3, T4, T5 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5) T5 {
|
||||
@ -305,14 +295,12 @@ func Variadic5[T1, T2, T3, T4, T5, V, R any](f func(T1, T2, T3, T4, T5, []V) R)
|
||||
return f(t1, t2, t3, t4, t5, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic5 converts a function taking 5 parameters and a final variadic argument into a function with 5 parameters but a final slice argument
|
||||
func Unvariadic5[T1, T2, T3, T4, T5, V, R any](f func(T1, T2, T3, T4, T5, ...V) R) func(T1, T2, T3, T4, T5, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe6 takes an initial value t0 and successively applies 6 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe6[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, T0, T1, T2, T3, T4, T5, T6 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6) T6 {
|
||||
@ -372,14 +360,12 @@ func Variadic6[T1, T2, T3, T4, T5, T6, V, R any](f func(T1, T2, T3, T4, T5, T6,
|
||||
return f(t1, t2, t3, t4, t5, t6, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic6 converts a function taking 6 parameters and a final variadic argument into a function with 6 parameters but a final slice argument
|
||||
func Unvariadic6[T1, T2, T3, T4, T5, T6, V, R any](f func(T1, T2, T3, T4, T5, T6, ...V) R) func(T1, T2, T3, T4, T5, T6, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe7 takes an initial value t0 and successively applies 7 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe7[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, T0, T1, T2, T3, T4, T5, T6, T7 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7) T7 {
|
||||
@ -442,14 +428,12 @@ func Variadic7[T1, T2, T3, T4, T5, T6, T7, V, R any](f func(T1, T2, T3, T4, T5,
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic7 converts a function taking 7 parameters and a final variadic argument into a function with 7 parameters but a final slice argument
|
||||
func Unvariadic7[T1, T2, T3, T4, T5, T6, T7, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe8 takes an initial value t0 and successively applies 8 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe8[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, T0, T1, T2, T3, T4, T5, T6, T7, T8 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8) T8 {
|
||||
@ -515,14 +499,12 @@ func Variadic8[T1, T2, T3, T4, T5, T6, T7, T8, V, R any](f func(T1, T2, T3, T4,
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic8 converts a function taking 8 parameters and a final variadic argument into a function with 8 parameters but a final slice argument
|
||||
func Unvariadic8[T1, T2, T3, T4, T5, T6, T7, T8, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe9 takes an initial value t0 and successively applies 9 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe9[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9) T9 {
|
||||
@ -591,14 +573,12 @@ func Variadic9[T1, T2, T3, T4, T5, T6, T7, T8, T9, V, R any](f func(T1, T2, T3,
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic9 converts a function taking 9 parameters and a final variadic argument into a function with 9 parameters but a final slice argument
|
||||
func Unvariadic9[T1, T2, T3, T4, T5, T6, T7, T8, T9, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe10 takes an initial value t0 and successively applies 10 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe10[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10) T10 {
|
||||
@ -670,14 +650,12 @@ func Variadic10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, V, R any](f func(T1, T2
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic10 converts a function taking 10 parameters and a final variadic argument into a function with 10 parameters but a final slice argument
|
||||
func Unvariadic10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe11 takes an initial value t0 and successively applies 11 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe11[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11) T11 {
|
||||
@ -752,14 +730,12 @@ func Variadic11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, V, R any](f func(T
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic11 converts a function taking 11 parameters and a final variadic argument into a function with 11 parameters but a final slice argument
|
||||
func Unvariadic11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe12 takes an initial value t0 and successively applies 12 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe12[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12) T12 {
|
||||
@ -837,14 +813,12 @@ func Variadic12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, V, R any](f f
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic12 converts a function taking 12 parameters and a final variadic argument into a function with 12 parameters but a final slice argument
|
||||
func Unvariadic12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe13 takes an initial value t0 and successively applies 13 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe13[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13) T13 {
|
||||
@ -925,14 +899,12 @@ func Variadic13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, V, R any
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic13 converts a function taking 13 parameters and a final variadic argument into a function with 13 parameters but a final slice argument
|
||||
func Unvariadic13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe14 takes an initial value t0 and successively applies 14 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe14[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, F14 ~func(T13) T14, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13, f14 F14) T14 {
|
||||
@ -1016,14 +988,12 @@ func Variadic14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, V,
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic14 converts a function taking 14 parameters and a final variadic argument into a function with 14 parameters but a final slice argument
|
||||
func Unvariadic14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, t14 T14, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe15 takes an initial value t0 and successively applies 15 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe15[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, F14 ~func(T13) T14, F15 ~func(T14) T15, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13, f14 F14, f15 F15) T15 {
|
||||
@ -1110,14 +1080,12 @@ func Variadic15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic15 converts a function taking 15 parameters and a final variadic argument into a function with 15 parameters but a final slice argument
|
||||
func Unvariadic15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, t14 T14, t15 T15, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe16 takes an initial value t0 and successively applies 16 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe16[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, F14 ~func(T13) T14, F15 ~func(T14) T15, F16 ~func(T15) T16, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13, f14 F14, f15 F15, f16 F16) T16 {
|
||||
@ -1207,14 +1175,12 @@ func Variadic16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic16 converts a function taking 16 parameters and a final variadic argument into a function with 16 parameters but a final slice argument
|
||||
func Unvariadic16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, t14 T14, t15 T15, t16 T16, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe17 takes an initial value t0 and successively applies 17 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe17[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, F14 ~func(T13) T14, F15 ~func(T14) T15, F16 ~func(T15) T16, F17 ~func(T16) T17, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13, f14 F14, f15 F15, f16 F16, f17 F17) T17 {
|
||||
@ -1307,14 +1273,12 @@ func Variadic17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic17 converts a function taking 17 parameters and a final variadic argument into a function with 17 parameters but a final slice argument
|
||||
func Unvariadic17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, t14 T14, t15 T15, t16 T16, t17 T17, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe18 takes an initial value t0 and successively applies 18 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe18[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, F14 ~func(T13) T14, F15 ~func(T14) T15, F16 ~func(T15) T16, F17 ~func(T16) T17, F18 ~func(T17) T18, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13, f14 F14, f15 F15, f16 F16, f17 F17, f18 F18) T18 {
|
||||
@ -1410,14 +1374,12 @@ func Variadic18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic18 converts a function taking 18 parameters and a final variadic argument into a function with 18 parameters but a final slice argument
|
||||
func Unvariadic18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, t14 T14, t15 T15, t16 T16, t17 T17, t18 T18, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe19 takes an initial value t0 and successively applies 19 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe19[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, F14 ~func(T13) T14, F15 ~func(T14) T15, F16 ~func(T15) T16, F17 ~func(T16) T17, F18 ~func(T17) T18, F19 ~func(T18) T19, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13, f14 F14, f15 F15, f16 F16, f17 F17, f18 F18, f19 F19) T19 {
|
||||
@ -1516,14 +1478,12 @@ func Variadic19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic19 converts a function taking 19 parameters and a final variadic argument into a function with 19 parameters but a final slice argument
|
||||
func Unvariadic19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, t14 T14, t15 T15, t16 T16, t17 T17, t18 T18, t19 T19, v []V) R {
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe20 takes an initial value t0 and successively applies 20 functions where the input of a function is the return value of the previous function
|
||||
// The final return value is the result of the last function application
|
||||
func Pipe20[F1 ~func(T0) T1, F2 ~func(T1) T2, F3 ~func(T2) T3, F4 ~func(T3) T4, F5 ~func(T4) T5, F6 ~func(T5) T6, F7 ~func(T6) T7, F8 ~func(T7) T8, F9 ~func(T8) T9, F10 ~func(T9) T10, F11 ~func(T10) T11, F12 ~func(T11) T12, F13 ~func(T12) T13, F14 ~func(T13) T14, F15 ~func(T14) T15, F16 ~func(T15) T16, F17 ~func(T16) T17, F18 ~func(T17) T18, F19 ~func(T18) T19, F20 ~func(T19) T20, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20 any](t0 T0, f1 F1, f2 F2, f3 F3, f4 F4, f5 F5, f6 F6, f7 F7, f8 F8, f9 F9, f10 F10, f11 F11, f12 F12, f13 F13, f14 F14, f15 F15, f16 F16, f17 F17, f18 F18, f19 F19, f20 F20) T20 {
|
||||
@ -1625,7 +1585,6 @@ func Variadic20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15
|
||||
return f(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Unvariadic20 converts a function taking 20 parameters and a final variadic argument into a function with 20 parameters but a final slice argument
|
||||
func Unvariadic20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, V, R any](f func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, ...V) R) func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, []V) R {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10, t11 T11, t12 T12, t13 T13, t14 T14, t15 T15, t16 T16, t17 T17, t18 T18, t19 T19, t20 T20, v []V) R {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 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
|
||||
|
||||
// optionize converts a nullary function to an option
|
||||
|
3
tuple/doc.go
Normal file
3
tuple/doc.go
Normal file
@ -0,0 +1,3 @@
|
||||
package tuple
|
||||
|
||||
//go:generate go run .. tuple --count 10 --filename gen.go
|
530
tuple/gen.go
Normal file
530
tuple/gen.go
Normal 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)
|
||||
})
|
||||
}
|
@ -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()))
|
||||
}
|
68
tuple/ord.go
68
tuple/ord.go
@ -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)
|
||||
})
|
||||
}
|
@ -2,76 +2,6 @@
|
||||
// consider to use arrays for simplicity
|
||||
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 {
|
||||
return t.F1
|
||||
}
|
||||
|
Reference in New Issue
Block a user