2023-07-07 22:31:06 +02:00
|
|
|
package either
|
|
|
|
|
|
|
|
|
|
import (
|
2023-07-13 22:24:04 +02:00
|
|
|
Apply "github.com/ibm/fp-go/internal/apply"
|
2023-07-07 22:31:06 +02:00
|
|
|
T "github.com/ibm/fp-go/tuple"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// SequenceT converts n inputs of higher kinded types into a higher kinded types of n strongly typed values, represented as a tuple
|
|
|
|
|
|
|
|
|
|
func SequenceT1[E, A any](a Either[E, A]) Either[E, T.Tuple1[A]] {
|
|
|
|
|
return Apply.SequenceT1(
|
2023-07-14 13:20:00 +02:00
|
|
|
Map[E, A, T.Tuple1[A]],
|
2023-07-07 22:31:06 +02:00
|
|
|
a,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SequenceT2[E, A, B any](a Either[E, A], b Either[E, B]) Either[E, T.Tuple2[A, B]] {
|
|
|
|
|
return Apply.SequenceT2(
|
2023-07-14 13:20:00 +02:00
|
|
|
Map[E, A, func(B) T.Tuple2[A, B]],
|
|
|
|
|
Ap[T.Tuple2[A, B], E, B],
|
2023-07-07 22:31:06 +02:00
|
|
|
|
|
|
|
|
a, b,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SequenceT3[E, A, B, C any](a Either[E, A], b Either[E, B], c Either[E, C]) Either[E, T.Tuple3[A, B, C]] {
|
|
|
|
|
return Apply.SequenceT3(
|
2023-07-14 13:20:00 +02:00
|
|
|
Map[E, A, func(B) func(C) T.Tuple3[A, B, C]],
|
|
|
|
|
Ap[func(C) T.Tuple3[A, B, C], E, B],
|
|
|
|
|
Ap[T.Tuple3[A, B, C], E, C],
|
2023-07-07 22:31:06 +02:00
|
|
|
|
|
|
|
|
a, b, c,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SequenceT4[E, A, B, C, D any](a Either[E, A], b Either[E, B], c Either[E, C], d Either[E, D]) Either[E, T.Tuple4[A, B, C, D]] {
|
|
|
|
|
return Apply.SequenceT4(
|
2023-07-14 13:20:00 +02:00
|
|
|
Map[E, A, func(B) func(C) func(D) T.Tuple4[A, B, C, D]],
|
|
|
|
|
Ap[func(C) func(D) T.Tuple4[A, B, C, D], E, B],
|
|
|
|
|
Ap[func(D) T.Tuple4[A, B, C, D], E, C],
|
|
|
|
|
Ap[T.Tuple4[A, B, C, D], E, D],
|
2023-07-07 22:31:06 +02:00
|
|
|
|
|
|
|
|
a, b, c, d,
|
|
|
|
|
)
|
|
|
|
|
}
|