1
0
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:
Dr. Carsten Leue
2023-09-11 13:48:51 +02:00
parent 7da9de6f41
commit a2a6a41993
26 changed files with 415 additions and 6 deletions

View File

@@ -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, A, B any](f func(A) Option[B]) func(GA) Option[GB] {
return RR.Traverse[GA](
Of[GB],
@@ -36,6 +36,22 @@ func TraverseRecord[K comparable, A, B any](f func(A) Option[B]) func(map[K]A) O
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, A, B any](f func(K, A) Option[B]) func(GA) Option[GB] {
return RR.TraverseWithIndex[GA](
Of[GB],
Map[GB, func(B) GB],
Ap[GB, B],
f,
)
}
// TraverseRecordWithIndex transforms a record of options into an option of a record
func TraverseRecordWithIndex[K comparable, A, B any](f func(K, A) Option[B]) func(map[K]A) Option[map[K]B] {
return TraverseRecordWithIndexG[map[K]A, map[K]B](f)
}
func SequenceRecordG[GA ~map[K]A, GOA ~map[K]Option[A], K comparable, A any](ma GOA) Option[GA] {
return TraverseRecordG[GOA, GA](F.Identity[Option[A]])(ma)
}