mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-17 00:07:49 +02:00
fix: add more examples
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@ -4,7 +4,6 @@ package readerioeither
|
|||||||
// This file was generated by robots at
|
// This file was generated by robots at
|
||||||
// 2023-08-11 11:37:34.0836986 +0200 CEST m=+0.009764601
|
// 2023-08-11 11:37:34.0836986 +0200 CEST m=+0.009764601
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
@ -4,13 +4,12 @@ package generic
|
|||||||
// This file was generated by robots at
|
// This file was generated by robots at
|
||||||
// 2023-08-11 11:37:34.0838811 +0200 CEST m=+0.009947101
|
// 2023-08-11 11:37:34.0838811 +0200 CEST m=+0.009947101
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
E "github.com/IBM/fp-go/either"
|
E "github.com/IBM/fp-go/either"
|
||||||
RE "github.com/IBM/fp-go/readerioeither/generic"
|
|
||||||
A "github.com/IBM/fp-go/internal/apply"
|
A "github.com/IBM/fp-go/internal/apply"
|
||||||
|
RE "github.com/IBM/fp-go/readerioeither/generic"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
// Package option defines the [Either] datastructure and its monadic operations
|
||||||
package either
|
package either
|
||||||
|
|
||||||
//go:generate go run .. either --count 10 --filename gen.go
|
//go:generate go run .. either --count 10 --filename gen.go
|
||||||
|
@ -182,7 +182,7 @@ func FromPredicate[E, A any](pred func(A) bool, onFalse func(A) E) func(A) Eithe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromNillable[E, A any](e E) func(*A) Either[E, *A] {
|
func FromNillable[A, E any](e E) func(*A) Either[E, *A] {
|
||||||
return FromPredicate(F.IsNonNil[A], F.Constant1[*A](e))
|
return FromPredicate(F.IsNonNil[A], F.Constant1[*A](e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
either/examples_create_test.go
Normal file
58
either/examples_create_test.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// Copyright (c) 2023 IBM Corp.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package either
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/IBM/fp-go/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleEither_creation() {
|
||||||
|
// Build an Either
|
||||||
|
leftValue := Left[string](fmt.Errorf("some error"))
|
||||||
|
rightValue := Right[error]("value")
|
||||||
|
|
||||||
|
// Build from a value
|
||||||
|
fromNillable := FromNillable[string](fmt.Errorf("value was nil"))
|
||||||
|
leftFromNil := fromNillable(nil)
|
||||||
|
value := "value"
|
||||||
|
rightFromPointer := fromNillable(&value)
|
||||||
|
|
||||||
|
// some predicate
|
||||||
|
isEven := func(num int) bool {
|
||||||
|
return num%2 == 0
|
||||||
|
}
|
||||||
|
fromEven := FromPredicate(isEven, errors.OnSome[int]("%d is an odd number"))
|
||||||
|
leftFromPred := fromEven(3)
|
||||||
|
rightFromPred := fromEven(4)
|
||||||
|
|
||||||
|
fmt.Println(leftValue)
|
||||||
|
fmt.Println(rightValue)
|
||||||
|
fmt.Println(leftFromNil)
|
||||||
|
fmt.Println(IsRight(rightFromPointer))
|
||||||
|
fmt.Println(leftFromPred)
|
||||||
|
fmt.Println(rightFromPred)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// Left[*errors.errorString, string](some error)
|
||||||
|
// Right[<nil>, string](value)
|
||||||
|
// Left[*errors.errorString, *string](value was nil)
|
||||||
|
// true
|
||||||
|
// Left[*errors.errorString, int](3 is an odd number)
|
||||||
|
// Right[<nil>, int](4)
|
||||||
|
|
||||||
|
}
|
64
either/examples_extract_test.go
Normal file
64
either/examples_extract_test.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Copyright (c) 2023 IBM Corp.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package either
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
F "github.com/IBM/fp-go/function"
|
||||||
|
N "github.com/IBM/fp-go/number"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleEither_extraction() {
|
||||||
|
leftValue := Left[int](fmt.Errorf("Division by Zero!"))
|
||||||
|
rightValue := Right[error](10)
|
||||||
|
|
||||||
|
// Convert Either[E, A] to A with a default value
|
||||||
|
leftWithDefault := GetOrElse(F.Constant1[error](0))(leftValue) // 0
|
||||||
|
rightWithDefault := GetOrElse(F.Constant1[error](0))(rightValue) // 10
|
||||||
|
|
||||||
|
// Apply a different function on Left(...)/Right(...)
|
||||||
|
doubleOrZero := Fold(F.Constant1[error](0), N.Mul(2)) // func(Either[error, int]) int
|
||||||
|
doubleFromLeft := doubleOrZero(leftValue) // 0
|
||||||
|
doubleFromRight := doubleOrZero(rightValue) // 20
|
||||||
|
|
||||||
|
// Pro-tip: Fold is short for the following:
|
||||||
|
doubleOrZeroBis := F.Flow2(
|
||||||
|
Map[error](N.Mul(2)),
|
||||||
|
GetOrElse(F.Constant1[error](0)),
|
||||||
|
)
|
||||||
|
doubleFromLeftBis := doubleOrZeroBis(leftValue) // 0
|
||||||
|
doubleFromRightBis := doubleOrZeroBis(rightValue) // 20
|
||||||
|
|
||||||
|
fmt.Println(leftValue)
|
||||||
|
fmt.Println(rightValue)
|
||||||
|
fmt.Println(leftWithDefault)
|
||||||
|
fmt.Println(rightWithDefault)
|
||||||
|
fmt.Println(doubleFromLeft)
|
||||||
|
fmt.Println(doubleFromRight)
|
||||||
|
fmt.Println(doubleFromLeftBis)
|
||||||
|
fmt.Println(doubleFromRightBis)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// Left[*errors.errorString, int](Division by Zero!)
|
||||||
|
// Right[<nil>, int](10)
|
||||||
|
// 0
|
||||||
|
// 10
|
||||||
|
// 0
|
||||||
|
// 20
|
||||||
|
// 0
|
||||||
|
// 20
|
||||||
|
}
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package either
|
package either
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
A "github.com/IBM/fp-go/internal/apply"
|
A "github.com/IBM/fp-go/internal/apply"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
|
@ -28,6 +28,22 @@ func OnNone(msg string, args ...any) func() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnSome generates a unary function that produces a formatted error
|
||||||
|
func OnSome[T any](msg string, args ...any) func(T) error {
|
||||||
|
l := len(args)
|
||||||
|
if l == 0 {
|
||||||
|
return func(value T) error {
|
||||||
|
return fmt.Errorf(msg, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return func(value T) error {
|
||||||
|
data := make([]any, l)
|
||||||
|
copy(data[1:], args)
|
||||||
|
data[0] = value
|
||||||
|
return fmt.Errorf(msg, data...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// OnError generates a unary function that produces a formatted error. The argument
|
// OnError generates a unary function that produces a formatted error. The argument
|
||||||
// to that function is the root cause of the error and the message will be augmented with
|
// to that function is the root cause of the error and the message will be augmented with
|
||||||
// a format string containing %w
|
// a format string containing %w
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// 2023-08-11 11:37:50.171038 +0200 CEST m=+0.031513801
|
// 2023-08-11 11:37:50.171038 +0200 CEST m=+0.031513801
|
||||||
|
|
||||||
package function
|
package function
|
||||||
|
|
||||||
// Combinations for a total of 1 arguments
|
// Combinations for a total of 1 arguments
|
||||||
|
|
||||||
// Bind1of1 takes a function with 1 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
// Bind1of1 takes a function with 1 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
||||||
@ -21,6 +22,7 @@ func Ignore1of1[T1 any, F ~func() R, R any](f F) func(T1) R {
|
|||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combinations for a total of 2 arguments
|
// Combinations for a total of 2 arguments
|
||||||
|
|
||||||
// Bind1of2 takes a function with 2 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
// Bind1of2 takes a function with 2 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
||||||
@ -73,6 +75,7 @@ func Ignore12of2[T1, T2 any, F ~func() R, R any](f F) func(T1, T2) R {
|
|||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combinations for a total of 3 arguments
|
// Combinations for a total of 3 arguments
|
||||||
|
|
||||||
// Bind1of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
// Bind1of3 takes a function with 3 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
||||||
@ -193,6 +196,7 @@ func Ignore123of3[T1, T2, T3 any, F ~func() R, R any](f F) func(T1, T2, T3) R {
|
|||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combinations for a total of 4 arguments
|
// Combinations for a total of 4 arguments
|
||||||
|
|
||||||
// Bind1of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
// Bind1of4 takes a function with 4 parameters and returns a new function with 1 parameters that will bind these parameters to the positions [1] of the original function.
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
// Package function implements function composition primitives, most prominently [Pipe2] and [Flow2]
|
||||||
package function
|
package function
|
||||||
|
|
||||||
//go:generate go run .. pipe --count 20 --filename gen.go
|
//go:generate go run .. pipe --count 20 --filename gen.go
|
||||||
|
@ -16,12 +16,14 @@ func Variadic0[V, R any](f func([]V) R) func(...V) R {
|
|||||||
return f(v)
|
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
|
// 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 {
|
func Unvariadic0[V, R any](f func(...V) R) func([]V) R {
|
||||||
return func(v []V) R {
|
return func(v []V) R {
|
||||||
return f(v...)
|
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
|
// 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
|
// 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 {
|
func Pipe1[F1 ~func(T0) T1, T0, T1 any](t0 T0, f1 F1) T1 {
|
||||||
@ -66,12 +68,14 @@ func Variadic1[T1, V, R any](f func(T1, []V) R) func(T1, ...V) R {
|
|||||||
return f(t1, v)
|
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
|
// 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 {
|
func Unvariadic1[T1, V, R any](f func(T1, ...V) R) func(T1, []V) R {
|
||||||
return func(t1 T1, v []V) R {
|
return func(t1 T1, v []V) R {
|
||||||
return f(t1, v...)
|
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
|
// 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
|
// 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 {
|
func Pipe2[F1 ~func(T0) T1, F2 ~func(T1) T2, T0, T1, T2 any](t0 T0, f1 F1, f2 F2) T2 {
|
||||||
@ -119,12 +123,14 @@ func Variadic2[T1, T2, V, R any](f func(T1, T2, []V) R) func(T1, T2, ...V) R {
|
|||||||
return f(t1, t2, v)
|
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
|
// 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 {
|
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 func(t1 T1, t2 T2, v []V) R {
|
||||||
return f(t1, t2, v...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -175,12 +181,14 @@ 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)
|
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
|
// 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 {
|
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 func(t1 T1, t2 T2, t3 T3, v []V) R {
|
||||||
return f(t1, t2, t3, v...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -234,12 +242,14 @@ 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)
|
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
|
// 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 {
|
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 func(t1 T1, t2 T2, t3 T3, t4 T4, v []V) R {
|
||||||
return f(t1, t2, t3, t4, v...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -296,12 +306,14 @@ 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)
|
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
|
// 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 {
|
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 func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, v []V) R {
|
||||||
return f(t1, t2, t3, t4, t5, v...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -361,12 +373,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -429,12 +443,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -500,12 +516,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -574,12 +592,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -651,12 +671,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -731,12 +753,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -814,12 +838,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -900,12 +926,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -989,12 +1017,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -1081,12 +1111,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -1176,12 +1208,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -1274,12 +1308,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -1375,12 +1411,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -1479,12 +1517,14 @@ 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)
|
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
|
// 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 {
|
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 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...)
|
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
|
// 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
|
// 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 {
|
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 {
|
||||||
@ -1586,6 +1626,7 @@ 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)
|
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
|
// 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 {
|
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 {
|
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 {
|
||||||
|
62
function/pipe_test.go
Normal file
62
function/pipe_test.go
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (c) 2023 IBM Corp.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package function
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func addSthg(value int) int {
|
||||||
|
return value + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func doSthgElse(value int) int {
|
||||||
|
return value * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
func doFinalSthg(value int) string {
|
||||||
|
return fmt.Sprintf("final value: %d", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Example() {
|
||||||
|
// start point
|
||||||
|
value := 1
|
||||||
|
// imperative style
|
||||||
|
value1 := addSthg(value) // 2
|
||||||
|
value2 := doSthgElse(value1) // 4
|
||||||
|
finalValueImperative := doFinalSthg(value2) // "final value: 4"
|
||||||
|
|
||||||
|
// the same but inline
|
||||||
|
finalValueInline := doFinalSthg(doSthgElse(addSthg(value)))
|
||||||
|
|
||||||
|
// with pipe
|
||||||
|
finalValuePipe := Pipe3(value, addSthg, doSthgElse, doFinalSthg)
|
||||||
|
|
||||||
|
// with flow
|
||||||
|
transform := Flow3(addSthg, doSthgElse, doFinalSthg)
|
||||||
|
finalValueFlow := transform(value)
|
||||||
|
|
||||||
|
fmt.Println(finalValueImperative)
|
||||||
|
fmt.Println(finalValueInline)
|
||||||
|
fmt.Println(finalValuePipe)
|
||||||
|
fmt.Println(finalValueFlow)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// final value: 4
|
||||||
|
// final value: 4
|
||||||
|
// final value: 4
|
||||||
|
// final value: 4
|
||||||
|
}
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package identity
|
package identity
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
A "github.com/IBM/fp-go/internal/apply"
|
A "github.com/IBM/fp-go/internal/apply"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package apply
|
package apply
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
F "github.com/IBM/fp-go/function"
|
F "github.com/IBM/fp-go/function"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package io
|
package io
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
G "github.com/IBM/fp-go/io/generic"
|
G "github.com/IBM/fp-go/io/generic"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
|
@ -3,10 +3,9 @@
|
|||||||
// 2023-08-11 11:38:07.3305497 +0200 CEST m=+0.014821301
|
// 2023-08-11 11:38:07.3305497 +0200 CEST m=+0.014821301
|
||||||
package generic
|
package generic
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
T "github.com/IBM/fp-go/tuple"
|
|
||||||
A "github.com/IBM/fp-go/internal/apply"
|
A "github.com/IBM/fp-go/internal/apply"
|
||||||
|
T "github.com/IBM/fp-go/tuple"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SequenceT1 converts 1 [func() T] into a [func() T.Tuple1[T1]]
|
// SequenceT1 converts 1 [func() T] into a [func() T.Tuple1[T1]]
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package ioeither
|
package ioeither
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
G "github.com/IBM/fp-go/ioeither/generic"
|
G "github.com/IBM/fp-go/ioeither/generic"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
// 2023-08-11 11:38:09.4489926 +0200 CEST m=+0.129900401
|
// 2023-08-11 11:38:09.4489926 +0200 CEST m=+0.129900401
|
||||||
package generic
|
package generic
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ET "github.com/IBM/fp-go/either"
|
ET "github.com/IBM/fp-go/either"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
|
||||||
A "github.com/IBM/fp-go/internal/apply"
|
A "github.com/IBM/fp-go/internal/apply"
|
||||||
|
T "github.com/IBM/fp-go/tuple"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GIOA]
|
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GIOA]
|
||||||
@ -16,7 +15,8 @@ func Eitherize0[GIOA ~func() ET.Either[error, R], F ~func() (R, error), R any](f
|
|||||||
return func() GIOA {
|
return func() GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e()
|
return e()
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GIOA]
|
// Uneitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GIOA]
|
||||||
@ -32,7 +32,8 @@ func Eitherize1[GIOA ~func() ET.Either[error, R], F ~func(T1) (R, error), T1, R
|
|||||||
return func(t1 T1) GIOA {
|
return func(t1 T1) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1)
|
return e(t1)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning a [GIOA]
|
// Uneitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning a [GIOA]
|
||||||
@ -85,7 +86,8 @@ func Eitherize2[GIOA ~func() ET.Either[error, R], F ~func(T1, T2) (R, error), T1
|
|||||||
return func(t1 T1, t2 T2) GIOA {
|
return func(t1 T1, t2 T2) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2)
|
return e(t1, t2)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning a [GIOA]
|
// Uneitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning a [GIOA]
|
||||||
@ -148,7 +150,8 @@ func Eitherize3[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3) (R, error)
|
|||||||
return func(t1 T1, t2 T2, t3 T3) GIOA {
|
return func(t1 T1, t2 T2, t3 T3) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3)
|
return e(t1, t2, t3)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning a [GIOA]
|
// Uneitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning a [GIOA]
|
||||||
@ -221,7 +224,8 @@ func Eitherize4[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4) (R, er
|
|||||||
return func(t1 T1, t2 T2, t3 T3, t4 T4) GIOA {
|
return func(t1 T1, t2 T2, t3 T3, t4 T4) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3, t4)
|
return e(t1, t2, t3, t4)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning a [GIOA]
|
// Uneitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning a [GIOA]
|
||||||
@ -304,7 +308,8 @@ func Eitherize5[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5) (R
|
|||||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) GIOA {
|
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3, t4, t5)
|
return e(t1, t2, t3, t4, t5)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning a [GIOA]
|
// Uneitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning a [GIOA]
|
||||||
@ -397,7 +402,8 @@ func Eitherize6[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
|||||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) GIOA {
|
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3, t4, t5, t6)
|
return e(t1, t2, t3, t4, t5, t6)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning a [GIOA]
|
// Uneitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning a [GIOA]
|
||||||
@ -500,7 +506,8 @@ func Eitherize7[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
|||||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) GIOA {
|
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3, t4, t5, t6, t7)
|
return e(t1, t2, t3, t4, t5, t6, t7)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning a [GIOA]
|
// Uneitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning a [GIOA]
|
||||||
@ -613,7 +620,8 @@ func Eitherize8[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
|||||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) GIOA {
|
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3, t4, t5, t6, t7, t8)
|
return e(t1, t2, t3, t4, t5, t6, t7, t8)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning a [GIOA]
|
// Uneitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning a [GIOA]
|
||||||
@ -736,7 +744,8 @@ func Eitherize9[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T6
|
|||||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) GIOA {
|
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3, t4, t5, t6, t7, t8, t9)
|
return e(t1, t2, t3, t4, t5, t6, t7, t8, t9)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning a [GIOA]
|
// Uneitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning a [GIOA]
|
||||||
@ -869,7 +878,8 @@ func Eitherize10[GIOA ~func() ET.Either[error, R], F ~func(T1, T2, T3, T4, T5, T
|
|||||||
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10) GIOA {
|
return func(t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9, t10 T10) GIOA {
|
||||||
return func() ET.Either[error, R] {
|
return func() ET.Either[error, R] {
|
||||||
return e(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)
|
return e(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uneitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning a [GIOA]
|
// Uneitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning a [GIOA]
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package iooption
|
package iooption
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
G "github.com/IBM/fp-go/iooption/generic"
|
G "github.com/IBM/fp-go/iooption/generic"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
// 2023-08-11 11:38:12.1210201 +0200 CEST m=+0.060813401
|
// 2023-08-11 11:38:12.1210201 +0200 CEST m=+0.060813401
|
||||||
package generic
|
package generic
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
T "github.com/IBM/fp-go/tuple"
|
|
||||||
O "github.com/IBM/fp-go/option"
|
|
||||||
A "github.com/IBM/fp-go/internal/apply"
|
A "github.com/IBM/fp-go/internal/apply"
|
||||||
|
O "github.com/IBM/fp-go/option"
|
||||||
|
T "github.com/IBM/fp-go/tuple"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SequenceT1 converts 1 [func() O.Option[T]] into a [func() O.Option[T.Tuple1[T1]]]
|
// SequenceT1 converts 1 [func() O.Option[T]] into a [func() O.Option[T.Tuple1[T1]]]
|
||||||
|
@ -30,6 +30,13 @@ func Add[T Number](left T) func(T) T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mul is a curried function used to add two numbers
|
||||||
|
func Mul[T Number](coeff T) func(T) T {
|
||||||
|
return func(value T) T {
|
||||||
|
return coeff * value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Inc is a function that increments a number
|
// Inc is a function that increments a number
|
||||||
func Inc[T Number](value T) T {
|
func Inc[T Number](value T) T {
|
||||||
return value + 1
|
return value + 1
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
// Package option defines the [Option] datastructure and its monadic operations
|
||||||
package option
|
package option
|
||||||
|
|
||||||
//go:generate go run .. option --count 10 --filename gen.go
|
//go:generate go run .. option --count 10 --filename gen.go
|
||||||
|
55
option/examples_create_test.go
Normal file
55
option/examples_create_test.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright (c) 2023 IBM Corp.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package option
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func ExampleOption_creation() {
|
||||||
|
|
||||||
|
// Build an Option
|
||||||
|
none1 := None[int]()
|
||||||
|
some1 := Some("value")
|
||||||
|
|
||||||
|
// Build from a value
|
||||||
|
fromNillable := FromNillable[string]
|
||||||
|
nonFromNil := fromNillable(nil) // None[*string]
|
||||||
|
value := "value"
|
||||||
|
someFromPointer := fromNillable(&value) // Some[*string](xxx)
|
||||||
|
|
||||||
|
// some predicate
|
||||||
|
isEven := func(num int) bool {
|
||||||
|
return num%2 == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fromEven := FromPredicate(isEven)
|
||||||
|
noneFromPred := fromEven(3) // None[int]
|
||||||
|
someFromPred := fromEven(4) // Some[int](4)
|
||||||
|
|
||||||
|
fmt.Println(none1)
|
||||||
|
fmt.Println(some1)
|
||||||
|
fmt.Println(nonFromNil)
|
||||||
|
fmt.Println(IsSome(someFromPointer))
|
||||||
|
fmt.Println(noneFromPred)
|
||||||
|
fmt.Println(someFromPred)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// None[int]
|
||||||
|
// Some[string](value)
|
||||||
|
// None[*string]
|
||||||
|
// true
|
||||||
|
// None[int]
|
||||||
|
// Some[int](4)
|
||||||
|
}
|
73
option/examples_extract_test.go
Normal file
73
option/examples_extract_test.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// Copyright (c) 2023 IBM Corp.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package option
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
F "github.com/IBM/fp-go/function"
|
||||||
|
N "github.com/IBM/fp-go/number"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleOption_extraction() {
|
||||||
|
|
||||||
|
noneValue := None[int]()
|
||||||
|
someValue := Of(42)
|
||||||
|
|
||||||
|
// Convert Option[T] to T
|
||||||
|
fromNone, okFromNone := Unwrap(noneValue) // 0, false
|
||||||
|
fromSome, okFromSome := Unwrap(someValue) // 42, true
|
||||||
|
|
||||||
|
// Convert Option[T] with a default value
|
||||||
|
noneWithDefault := GetOrElse(F.Constant(0))(noneValue) // 0
|
||||||
|
someWithDefault := GetOrElse(F.Constant(0))(someValue) // 42
|
||||||
|
|
||||||
|
// Apply a different function on None/Some(...)
|
||||||
|
doubleOrZero := Fold(
|
||||||
|
F.Constant(0), // none case
|
||||||
|
N.Mul(2), // some case
|
||||||
|
) // func(ma Option[int]) int
|
||||||
|
|
||||||
|
doubleFromNone := doubleOrZero(noneValue) // 0
|
||||||
|
doubleFromSome := doubleOrZero(someValue) // 84
|
||||||
|
|
||||||
|
// Pro-tip: Fold is short for the following:
|
||||||
|
doubleOfZeroBis := F.Flow2(
|
||||||
|
Map(N.Mul(2)), // some case
|
||||||
|
GetOrElse(F.Constant(0)), // none case
|
||||||
|
)
|
||||||
|
doubleFromNoneBis := doubleOfZeroBis(noneValue) // 0
|
||||||
|
doubleFromSomeBis := doubleOfZeroBis(someValue) // 84
|
||||||
|
|
||||||
|
fmt.Printf("%d, %t\n", fromNone, okFromNone)
|
||||||
|
fmt.Printf("%d, %t\n", fromSome, okFromSome)
|
||||||
|
fmt.Println(noneWithDefault)
|
||||||
|
fmt.Println(someWithDefault)
|
||||||
|
fmt.Println(doubleFromNone)
|
||||||
|
fmt.Println(doubleFromSome)
|
||||||
|
fmt.Println(doubleFromNoneBis)
|
||||||
|
fmt.Println(doubleFromSomeBis)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 0, false
|
||||||
|
// 42, true
|
||||||
|
// 0
|
||||||
|
// 42
|
||||||
|
// 0
|
||||||
|
// 84
|
||||||
|
// 0
|
||||||
|
// 84
|
||||||
|
}
|
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
package option
|
package option
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
A "github.com/IBM/fp-go/internal/apply"
|
A "github.com/IBM/fp-go/internal/apply"
|
||||||
T "github.com/IBM/fp-go/tuple"
|
T "github.com/IBM/fp-go/tuple"
|
||||||
)
|
)
|
||||||
|
|
||||||
// optionize converts a nullary function to an option
|
// optionize converts a nullary function to an option
|
||||||
func optionize[R any](f func() (R, bool)) Option[R] {
|
func optionize[R any](f func() (R, bool)) Option[R] {
|
||||||
if r, ok := f(); ok {
|
if r, ok := f(); ok {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package reader
|
package reader
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
G "github.com/IBM/fp-go/reader/generic"
|
G "github.com/IBM/fp-go/reader/generic"
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// 2023-08-11 11:38:23.1402159 +0200 CEST m=+0.021332501
|
// 2023-08-11 11:38:23.1402159 +0200 CEST m=+0.021332501
|
||||||
package generic
|
package generic
|
||||||
|
|
||||||
|
|
||||||
// From0 converts a function with 1 parameters returning a [R] into a function with 0 parameters returning a [GRA]
|
// From0 converts a function with 1 parameters returning a [R] into a function with 0 parameters returning a [GRA]
|
||||||
// The first parameter is considered to be the context [C].
|
// The first parameter is considered to be the context [C].
|
||||||
func From0[GRA ~func(C) R, F ~func(C) R, C, R any](f F) func() GRA {
|
func From0[GRA ~func(C) R, F ~func(C) R, C, R any](f F) func() GRA {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package readerioeither
|
package readerioeither
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
G "github.com/IBM/fp-go/readerioeither/generic"
|
G "github.com/IBM/fp-go/readerioeither/generic"
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// 2023-08-11 11:38:26.9556725 +0200 CEST m=+0.033178001
|
// 2023-08-11 11:38:26.9556725 +0200 CEST m=+0.033178001
|
||||||
package generic
|
package generic
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
E "github.com/IBM/fp-go/either"
|
E "github.com/IBM/fp-go/either"
|
||||||
RD "github.com/IBM/fp-go/reader/generic"
|
RD "github.com/IBM/fp-go/reader/generic"
|
||||||
@ -23,7 +22,8 @@ func Eitherize0[GRA ~func(C) GIOA, F ~func(C) (R, error), GIOA ~func() E.Either[
|
|||||||
return From0[GRA](func(r C) func() (R, error) {
|
return From0[GRA](func(r C) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r)
|
return f(r)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From1 converts a function with 2 parameters returning a tuple into a function with 1 parameters returning a [GRA]
|
// From1 converts a function with 2 parameters returning a tuple into a function with 1 parameters returning a [GRA]
|
||||||
@ -40,7 +40,8 @@ func Eitherize1[GRA ~func(C) GIOA, F ~func(C, T0) (R, error), GIOA ~func() E.Eit
|
|||||||
return From1[GRA](func(r C, t0 T0) func() (R, error) {
|
return From1[GRA](func(r C, t0 T0) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0)
|
return f(r, t0)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From2 converts a function with 3 parameters returning a tuple into a function with 2 parameters returning a [GRA]
|
// From2 converts a function with 3 parameters returning a tuple into a function with 2 parameters returning a [GRA]
|
||||||
@ -57,7 +58,8 @@ func Eitherize2[GRA ~func(C) GIOA, F ~func(C, T0, T1) (R, error), GIOA ~func() E
|
|||||||
return From2[GRA](func(r C, t0 T0, t1 T1) func() (R, error) {
|
return From2[GRA](func(r C, t0 T0, t1 T1) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1)
|
return f(r, t0, t1)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From3 converts a function with 4 parameters returning a tuple into a function with 3 parameters returning a [GRA]
|
// From3 converts a function with 4 parameters returning a tuple into a function with 3 parameters returning a [GRA]
|
||||||
@ -74,7 +76,8 @@ func Eitherize3[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2) (R, error), GIOA ~func
|
|||||||
return From3[GRA](func(r C, t0 T0, t1 T1, t2 T2) func() (R, error) {
|
return From3[GRA](func(r C, t0 T0, t1 T1, t2 T2) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2)
|
return f(r, t0, t1, t2)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From4 converts a function with 5 parameters returning a tuple into a function with 4 parameters returning a [GRA]
|
// From4 converts a function with 5 parameters returning a tuple into a function with 4 parameters returning a [GRA]
|
||||||
@ -91,7 +94,8 @@ func Eitherize4[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3) (R, error), GIOA ~
|
|||||||
return From4[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3) func() (R, error) {
|
return From4[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2, t3)
|
return f(r, t0, t1, t2, t3)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From5 converts a function with 6 parameters returning a tuple into a function with 5 parameters returning a [GRA]
|
// From5 converts a function with 6 parameters returning a tuple into a function with 5 parameters returning a [GRA]
|
||||||
@ -108,7 +112,8 @@ func Eitherize5[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4) (R, error), GI
|
|||||||
return From5[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) func() (R, error) {
|
return From5[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2, t3, t4)
|
return f(r, t0, t1, t2, t3, t4)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From6 converts a function with 7 parameters returning a tuple into a function with 6 parameters returning a [GRA]
|
// From6 converts a function with 7 parameters returning a tuple into a function with 6 parameters returning a [GRA]
|
||||||
@ -125,7 +130,8 @@ func Eitherize6[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5) (R, error)
|
|||||||
return From6[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) func() (R, error) {
|
return From6[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2, t3, t4, t5)
|
return f(r, t0, t1, t2, t3, t4, t5)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From7 converts a function with 8 parameters returning a tuple into a function with 7 parameters returning a [GRA]
|
// From7 converts a function with 8 parameters returning a tuple into a function with 7 parameters returning a [GRA]
|
||||||
@ -142,7 +148,8 @@ func Eitherize7[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6) (R, er
|
|||||||
return From7[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) func() (R, error) {
|
return From7[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2, t3, t4, t5, t6)
|
return f(r, t0, t1, t2, t3, t4, t5, t6)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From8 converts a function with 9 parameters returning a tuple into a function with 8 parameters returning a [GRA]
|
// From8 converts a function with 9 parameters returning a tuple into a function with 8 parameters returning a [GRA]
|
||||||
@ -159,7 +166,8 @@ func Eitherize8[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) (R
|
|||||||
return From8[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) func() (R, error) {
|
return From8[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7)
|
return f(r, t0, t1, t2, t3, t4, t5, t6, t7)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From9 converts a function with 10 parameters returning a tuple into a function with 9 parameters returning a [GRA]
|
// From9 converts a function with 10 parameters returning a tuple into a function with 9 parameters returning a [GRA]
|
||||||
@ -176,7 +184,8 @@ func Eitherize9[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8
|
|||||||
return From9[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) func() (R, error) {
|
return From9[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8)
|
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// From10 converts a function with 11 parameters returning a tuple into a function with 10 parameters returning a [GRA]
|
// From10 converts a function with 11 parameters returning a tuple into a function with 10 parameters returning a [GRA]
|
||||||
@ -193,5 +202,6 @@ func Eitherize10[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T
|
|||||||
return From10[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) func() (R, error) {
|
return From10[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) func() (R, error) {
|
||||||
return func() (R, error) {
|
return func() (R, error) {
|
||||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
|
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
546
tuple/gen.go
546
tuple/gen.go
@ -4,10 +4,9 @@
|
|||||||
|
|
||||||
package tuple
|
package tuple
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
M "github.com/IBM/fp-go/monoid"
|
M "github.com/IBM/fp-go/monoid"
|
||||||
O "github.com/IBM/fp-go/ord"
|
O "github.com/IBM/fp-go/ord"
|
||||||
)
|
)
|
||||||
@ -138,7 +137,9 @@ func Monoid1[T1 any](m1 M.Monoid[T1]) M.Monoid[Tuple1[T1]] {
|
|||||||
// Ord1 creates n [Ord] for a [Tuple1] based on 1 [Ord]s for the contained types
|
// 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]] {
|
func Ord1[T1 any](o1 O.Ord[T1]) O.Ord[Tuple1[T1]] {
|
||||||
return O.MakeOrd(func(l, r Tuple1[T1]) int {
|
return O.MakeOrd(func(l, r Tuple1[T1]) int {
|
||||||
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
|
if c := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
|
return c
|
||||||
|
}
|
||||||
return 0
|
return 0
|
||||||
}, func(l, r Tuple1[T1]) bool {
|
}, func(l, r Tuple1[T1]) bool {
|
||||||
return o1.Equals(l.F1, r.F1)
|
return o1.Equals(l.F1, r.F1)
|
||||||
@ -172,10 +173,14 @@ func (t Tuple1[T1]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple1]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple1]
|
||||||
func (t *Tuple1[T1]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple1[T1]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -231,8 +236,12 @@ func Monoid2[T1, T2 any](m1 M.Monoid[T1], m2 M.Monoid[T2]) M.Monoid[Tuple2[T1, T
|
|||||||
// Ord2 creates n [Ord] for a [Tuple2] based on 2 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
return O.MakeOrd(func(l, r Tuple2[T1, T2]) int {
|
||||||
if c:= o1.Compare(l.F1, r.F1); c != 0 {return c}
|
if c := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
return c
|
||||||
|
}
|
||||||
|
if c := o2.Compare(l.F2, r.F2); c != 0 {
|
||||||
|
return c
|
||||||
|
}
|
||||||
return 0
|
return 0
|
||||||
}, func(l, r Tuple2[T1, T2]) bool {
|
}, func(l, r Tuple2[T1, T2]) bool {
|
||||||
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2)
|
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2)
|
||||||
@ -267,13 +276,20 @@ func (t Tuple2[T1, T2]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple2]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple2]
|
||||||
func (t *Tuple2[T1, T2]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple2[T1, T2]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,9 +346,15 @@ func Monoid3[T1, T2, T3 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T3])
|
|||||||
// Ord3 creates n [Ord] for a [Tuple3] based on 3 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
return c
|
||||||
if c:= o3.Compare(l.F3, r.F3); 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
|
return 0
|
||||||
}, func(l, r Tuple3[T1, T2, T3]) bool {
|
}, 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)
|
return o1.Equals(l.F1, r.F1) && o2.Equals(l.F2, r.F2) && o3.Equals(l.F3, r.F3)
|
||||||
@ -368,15 +390,25 @@ func (t Tuple3[T1, T2, T3]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple3]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple3]
|
||||||
func (t *Tuple3[T1, T2, T3]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple3[T1, T2, T3]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,10 +467,18 @@ func Monoid4[T1, T2, T3, T4 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Monoid[T
|
|||||||
// Ord4 creates n [Ord] for a [Tuple4] based on 4 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
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 := 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
|
return 0
|
||||||
}, func(l, r Tuple4[T1, T2, T3, T4]) bool {
|
}, 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)
|
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)
|
||||||
@ -475,17 +515,30 @@ func (t Tuple4[T1, T2, T3, T4]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple4]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple4]
|
||||||
func (t *Tuple4[T1, T2, T3, T4]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple4[T1, T2, T3, T4]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 3 {
|
if l > 3 {
|
||||||
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {return err}
|
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {
|
||||||
}}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,11 +599,21 @@ func Monoid5[T1, T2, T3, T4, T5 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.Mono
|
|||||||
// Ord5 creates n [Ord] for a [Tuple5] based on 5 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
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 := o2.Compare(l.F2, r.F2); c != 0 {
|
||||||
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
|
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
|
return 0
|
||||||
}, func(l, r Tuple5[T1, T2, T3, T4, T5]) bool {
|
}, 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)
|
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)
|
||||||
@ -588,19 +651,35 @@ func (t Tuple5[T1, T2, T3, T4, T5]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple5]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple5]
|
||||||
func (t *Tuple5[T1, T2, T3, T4, T5]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple5[T1, T2, T3, T4, T5]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 3 {
|
if l > 3 {
|
||||||
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {return err}
|
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 4 {
|
if l > 4 {
|
||||||
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {return err}
|
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {
|
||||||
}}}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,12 +742,24 @@ func Monoid6[T1, T2, T3, T4, T5, T6 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m3 M.
|
|||||||
// Ord6 creates n [Ord] for a [Tuple6] based on 6 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
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 := o2.Compare(l.F2, r.F2); c != 0 {
|
||||||
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
|
return c
|
||||||
if c:= o6.Compare(l.F6, r.F6); 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
|
return 0
|
||||||
}, func(l, r Tuple6[T1, T2, T3, T4, T5, T6]) bool {
|
}, 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)
|
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)
|
||||||
@ -707,21 +798,40 @@ func (t Tuple6[T1, T2, T3, T4, T5, T6]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple6]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple6]
|
||||||
func (t *Tuple6[T1, T2, T3, T4, T5, T6]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple6[T1, T2, T3, T4, T5, T6]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 3 {
|
if l > 3 {
|
||||||
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {return err}
|
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 4 {
|
if l > 4 {
|
||||||
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {return err}
|
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 5 {
|
if l > 5 {
|
||||||
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {return err}
|
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {
|
||||||
}}}}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -786,13 +896,27 @@ func Monoid7[T1, T2, T3, T4, T5, T6, T7 any](m1 M.Monoid[T1], m2 M.Monoid[T2], m
|
|||||||
// Ord7 creates n [Ord] for a [Tuple7] based on 7 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
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 := o2.Compare(l.F2, r.F2); c != 0 {
|
||||||
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
|
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 := 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
|
return 0
|
||||||
}, func(l, r Tuple7[T1, T2, T3, T4, T5, T6, T7]) bool {
|
}, 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)
|
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)
|
||||||
@ -832,23 +956,45 @@ func (t Tuple7[T1, T2, T3, T4, T5, T6, T7]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple7]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple7]
|
||||||
func (t *Tuple7[T1, T2, T3, T4, T5, T6, T7]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple7[T1, T2, T3, T4, T5, T6, T7]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 3 {
|
if l > 3 {
|
||||||
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {return err}
|
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 4 {
|
if l > 4 {
|
||||||
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {return err}
|
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 5 {
|
if l > 5 {
|
||||||
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {return err}
|
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 6 {
|
if l > 6 {
|
||||||
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {return err}
|
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {
|
||||||
}}}}}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -915,14 +1061,30 @@ func Monoid8[T1, T2, T3, T4, T5, T6, T7, T8 any](m1 M.Monoid[T1], m2 M.Monoid[T2
|
|||||||
// Ord8 creates n [Ord] for a [Tuple8] based on 8 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
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 := o2.Compare(l.F2, r.F2); c != 0 {
|
||||||
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
|
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 := o3.Compare(l.F3, r.F3); c != 0 {
|
||||||
if c:= o8.Compare(l.F8, r.F8); c != 0 {return c}
|
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
|
return 0
|
||||||
}, func(l, r Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) bool {
|
}, 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)
|
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)
|
||||||
@ -963,25 +1125,50 @@ func (t Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple8]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple8]
|
||||||
func (t *Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 3 {
|
if l > 3 {
|
||||||
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {return err}
|
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 4 {
|
if l > 4 {
|
||||||
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {return err}
|
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 5 {
|
if l > 5 {
|
||||||
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {return err}
|
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 6 {
|
if l > 6 {
|
||||||
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {return err}
|
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 7 {
|
if l > 7 {
|
||||||
if err := json.Unmarshal(tmp[7], &t.F8); err != nil {return err}
|
if err := json.Unmarshal(tmp[7], &t.F8); err != nil {
|
||||||
}}}}}}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1050,15 +1237,33 @@ func Monoid9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](m1 M.Monoid[T1], m2 M.Monoi
|
|||||||
// Ord9 creates n [Ord] for a [Tuple9] based on 9 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
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 := o2.Compare(l.F2, r.F2); c != 0 {
|
||||||
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
|
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 := o3.Compare(l.F3, r.F3); c != 0 {
|
||||||
if c:= o8.Compare(l.F8, r.F8); c != 0 {return c}
|
return c
|
||||||
if c:= o9.Compare(l.F9, r.F9); 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
|
return 0
|
||||||
}, func(l, r Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) bool {
|
}, 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)
|
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)
|
||||||
@ -1100,27 +1305,55 @@ func (t Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) MarshalJSON() ([]byte, error
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple9]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple9]
|
||||||
func (t *Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 3 {
|
if l > 3 {
|
||||||
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {return err}
|
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 4 {
|
if l > 4 {
|
||||||
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {return err}
|
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 5 {
|
if l > 5 {
|
||||||
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {return err}
|
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 6 {
|
if l > 6 {
|
||||||
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {return err}
|
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 7 {
|
if l > 7 {
|
||||||
if err := json.Unmarshal(tmp[7], &t.F8); err != nil {return err}
|
if err := json.Unmarshal(tmp[7], &t.F8); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 8 {
|
if l > 8 {
|
||||||
if err := json.Unmarshal(tmp[8], &t.F9); err != nil {return err}
|
if err := json.Unmarshal(tmp[8], &t.F9); err != nil {
|
||||||
}}}}}}}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1191,16 +1424,36 @@ func Monoid10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any](m1 M.Monoid[T1], m2 M
|
|||||||
// Ord10 creates n [Ord] for a [Tuple10] based on 10 [Ord]s for the contained types
|
// 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]] {
|
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 {
|
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 := o1.Compare(l.F1, r.F1); c != 0 {
|
||||||
if c:= o2.Compare(l.F2, r.F2); c != 0 {return c}
|
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 := o2.Compare(l.F2, r.F2); c != 0 {
|
||||||
if c:= o5.Compare(l.F5, r.F5); c != 0 {return c}
|
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 := o3.Compare(l.F3, r.F3); c != 0 {
|
||||||
if c:= o8.Compare(l.F8, r.F8); c != 0 {return c}
|
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}
|
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
|
return 0
|
||||||
}, func(l, r Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) bool {
|
}, 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)
|
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)
|
||||||
@ -1243,29 +1496,60 @@ func (t Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) MarshalJSON() ([]byte,
|
|||||||
// UnmarshalJSON unmarshals a JSON array into a [Tuple10]
|
// UnmarshalJSON unmarshals a JSON array into a [Tuple10]
|
||||||
func (t *Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) UnmarshalJSON(data []byte) error {
|
func (t *Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) UnmarshalJSON(data []byte) error {
|
||||||
var tmp []json.RawMessage
|
var tmp []json.RawMessage
|
||||||
if err := json.Unmarshal(data, &tmp); err != nil {return err}
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
l := len(tmp)
|
l := len(tmp)
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {return err}
|
if err := json.Unmarshal(tmp[0], &t.F1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {return err}
|
if err := json.Unmarshal(tmp[1], &t.F2); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 2 {
|
if l > 2 {
|
||||||
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {return err}
|
if err := json.Unmarshal(tmp[2], &t.F3); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 3 {
|
if l > 3 {
|
||||||
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {return err}
|
if err := json.Unmarshal(tmp[3], &t.F4); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 4 {
|
if l > 4 {
|
||||||
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {return err}
|
if err := json.Unmarshal(tmp[4], &t.F5); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 5 {
|
if l > 5 {
|
||||||
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {return err}
|
if err := json.Unmarshal(tmp[5], &t.F6); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 6 {
|
if l > 6 {
|
||||||
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {return err}
|
if err := json.Unmarshal(tmp[6], &t.F7); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 7 {
|
if l > 7 {
|
||||||
if err := json.Unmarshal(tmp[7], &t.F8); err != nil {return err}
|
if err := json.Unmarshal(tmp[7], &t.F8); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 8 {
|
if l > 8 {
|
||||||
if err := json.Unmarshal(tmp[8], &t.F9); err != nil {return err}
|
if err := json.Unmarshal(tmp[8], &t.F9); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if l > 9 {
|
if l > 9 {
|
||||||
if err := json.Unmarshal(tmp[9], &t.F10); err != nil {return err}
|
if err := json.Unmarshal(tmp[9], &t.F10); err != nil {
|
||||||
}}}}}}}}}}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func doubleAndLog(data int) Writer[[]string, int] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Example() {
|
func ExampleWriter_logging() {
|
||||||
|
|
||||||
m := A.Monoid[string]()
|
m := A.Monoid[string]()
|
||||||
s := M.ToSemigroup(m)
|
s := M.ToSemigroup(m)
|
||||||
|
Reference in New Issue
Block a user