1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-06-17 00:07:49 +02:00
Files
fp-go/tuple/tuple.go
Dr. Carsten Leue a18a04ce39 fix: code generation for tuple
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-07-13 17:34:13 +02:00

28 lines
728 B
Go

// Package tuple contains type definitions and functions for data structures for tuples of heterogenous types. For homogeneous types
// consider to use arrays for simplicity
package tuple
func First[T1, T2 any](t Tuple2[T1, T2]) T1 {
return t.F1
}
func Second[T1, T2 any](t Tuple2[T1, T2]) T2 {
return t.F2
}
func Swap[T1, T2 any](t Tuple2[T1, T2]) Tuple2[T2, T1] {
return MakeTuple2(t.F2, t.F1)
}
func Of[T1, T2 any](e T2) func(T1) Tuple2[T1, T2] {
return func(t T1) Tuple2[T1, T2] {
return MakeTuple2(t, e)
}
}
func BiMap[E, G, A, B any](mapSnd func(E) G, mapFst func(A) B) func(Tuple2[A, E]) Tuple2[B, G] {
return func(t Tuple2[A, E]) Tuple2[B, G] {
return MakeTuple2(mapFst(First(t)), mapSnd(Second(t)))
}
}