mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: add missing withIndex methods
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -20,7 +20,7 @@ import (
|
||||
RA "github.com/IBM/fp-go/internal/array"
|
||||
)
|
||||
|
||||
// TraverseArray transforms an array
|
||||
// TraverseArrayG transforms an array
|
||||
func TraverseArrayG[GA ~[]A, GB ~[]B, E, A, B any](f func(A) Either[E, B]) func(GA) Either[E, GB] {
|
||||
return RA.Traverse[GA](
|
||||
Of[E, GB],
|
||||
@@ -36,6 +36,22 @@ func TraverseArray[E, A, B any](f func(A) Either[E, B]) func([]A) Either[E, []B]
|
||||
return TraverseArrayG[[]A, []B](f)
|
||||
}
|
||||
|
||||
// TraverseArrayWithIndexG transforms an array
|
||||
func TraverseArrayWithIndexG[GA ~[]A, GB ~[]B, E, A, B any](f func(int, A) Either[E, B]) func(GA) Either[E, GB] {
|
||||
return RA.TraverseWithIndex[GA](
|
||||
Of[E, GB],
|
||||
Map[E, GB, func(B) GB],
|
||||
Ap[GB, E, B],
|
||||
|
||||
f,
|
||||
)
|
||||
}
|
||||
|
||||
// TraverseArrayWithIndex transforms an array
|
||||
func TraverseArrayWithIndex[E, A, B any](f func(int, A) Either[E, B]) func([]A) Either[E, []B] {
|
||||
return TraverseArrayWithIndexG[[]A, []B](f)
|
||||
}
|
||||
|
||||
func SequenceArrayG[GA ~[]A, GOA ~[]Either[E, A], E, A any](ma GOA) Either[E, GA] {
|
||||
return TraverseArrayG[GOA, GA](F.Identity[Either[E, A]])(ma)
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import (
|
||||
RR "github.com/IBM/fp-go/internal/record"
|
||||
)
|
||||
|
||||
// TraverseRecord transforms a record of options into an option of a record
|
||||
// TraverseRecordG transforms a record of options into an option of a record
|
||||
func TraverseRecordG[GA ~map[K]A, GB ~map[K]B, K comparable, E, A, B any](f func(A) Either[E, B]) func(GA) Either[E, GB] {
|
||||
return RR.Traverse[GA](
|
||||
Of[E, GB],
|
||||
@@ -35,6 +35,21 @@ func TraverseRecord[K comparable, E, A, B any](f func(A) Either[E, B]) func(map[
|
||||
return TraverseRecordG[map[K]A, map[K]B](f)
|
||||
}
|
||||
|
||||
// TraverseRecordWithIndexG transforms a record of options into an option of a record
|
||||
func TraverseRecordWithIndexG[GA ~map[K]A, GB ~map[K]B, K comparable, E, A, B any](f func(K, A) Either[E, B]) func(GA) Either[E, GB] {
|
||||
return RR.TraverseWithIndex[GA](
|
||||
Of[E, GB],
|
||||
Map[E, GB, func(B) GB],
|
||||
Ap[GB, E, B],
|
||||
f,
|
||||
)
|
||||
}
|
||||
|
||||
// TraverseRecordWithIndex transforms a record of eithers into an either of a record
|
||||
func TraverseRecordWithIndex[K comparable, E, A, B any](f func(K, A) Either[E, B]) func(map[K]A) Either[E, map[K]B] {
|
||||
return TraverseRecordWithIndexG[map[K]A, map[K]B](f)
|
||||
}
|
||||
|
||||
func SequenceRecordG[GA ~map[K]A, GOA ~map[K]Either[E, A], K comparable, E, A any](ma GOA) Either[E, GA] {
|
||||
return TraverseRecordG[GOA, GA](F.Identity[Either[E, A]])(ma)
|
||||
}
|
||||
|
Reference in New Issue
Block a user