mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-25 22:21:49 +02:00
fix: code generation for tuple
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -2,76 +2,6 @@
|
||||
// consider to use arrays for simplicity
|
||||
package tuple
|
||||
|
||||
// Tuple1 is a structure carrying one element
|
||||
type Tuple1[T1 any] struct {
|
||||
F1 T1
|
||||
}
|
||||
|
||||
// Tuple2 is a structure carrying two elements
|
||||
type Tuple2[T1, T2 any] struct {
|
||||
F1 T1
|
||||
F2 T2
|
||||
}
|
||||
|
||||
// Tuple3 is a structure carrying three elements
|
||||
type Tuple3[T1, T2, T3 any] struct {
|
||||
F1 T1
|
||||
F2 T2
|
||||
F3 T3
|
||||
}
|
||||
|
||||
// Tuple4 is a structure carrying four elements
|
||||
type Tuple4[T1, T2, T3, T4 any] struct {
|
||||
F1 T1
|
||||
F2 T2
|
||||
F3 T3
|
||||
F4 T4
|
||||
}
|
||||
|
||||
func MakeTuple1[T1 any](t1 T1) Tuple1[T1] {
|
||||
return Tuple1[T1]{F1: t1}
|
||||
}
|
||||
|
||||
func MakeTuple2[T1, T2 any](t1 T1, t2 T2) Tuple2[T1, T2] {
|
||||
return Tuple2[T1, T2]{F1: t1, F2: t2}
|
||||
}
|
||||
|
||||
func MakeTuple3[T1, T2, T3 any](t1 T1, t2 T2, t3 T3) Tuple3[T1, T2, T3] {
|
||||
return Tuple3[T1, T2, T3]{F1: t1, F2: t2, F3: t3}
|
||||
}
|
||||
|
||||
func MakeTuple4[T1, T2, T3, T4 any](t1 T1, t2 T2, t3 T3, t4 T4) Tuple4[T1, T2, T3, T4] {
|
||||
return Tuple4[T1, T2, T3, T4]{F1: t1, F2: t2, F3: t3, F4: t4}
|
||||
}
|
||||
|
||||
// Tupled2 converts a function that accepts two parameters into a function that accepts a tuple
|
||||
func Tupled2[T1, T2, R any](f func(t1 T1, t2 T2) R) func(Tuple2[T1, T2]) R {
|
||||
return func(t Tuple2[T1, T2]) R {
|
||||
return f(t.F1, t.F2)
|
||||
}
|
||||
}
|
||||
|
||||
// Tupled3 converts a function that accepts three parameters into a function that accepts a tuple
|
||||
func Tupled3[T1, T2, T3, R any](f func(t1 T1, t2 T2, t3 T3) R) func(Tuple3[T1, T2, T3]) R {
|
||||
return func(t Tuple3[T1, T2, T3]) R {
|
||||
return f(t.F1, t.F2, t.F3)
|
||||
}
|
||||
}
|
||||
|
||||
// Untupled2 converts a function that accepts a tuple into a function that accepts two parameters
|
||||
func Untupled2[T1, T2, R any](f func(Tuple2[T1, T2]) R) func(T1, T2) R {
|
||||
return func(t1 T1, t2 T2) R {
|
||||
return f(MakeTuple2(t1, t2))
|
||||
}
|
||||
}
|
||||
|
||||
// Untupled3 converts a function that accepts a tuple into a function that accepts three parameters
|
||||
func Untupled3[T1, T2, T3, R any](f func(Tuple3[T1, T2, T3]) R) func(T1, T2, T3) R {
|
||||
return func(t1 T1, t2 T2, t3 T3) R {
|
||||
return f(MakeTuple3(t1, t2, t3))
|
||||
}
|
||||
}
|
||||
|
||||
func First[T1, T2 any](t Tuple2[T1, T2]) T1 {
|
||||
return t.F1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user