mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: migrate traversal
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
|||||||
RR "github.com/IBM/fp-go/v2/internal/record"
|
RR "github.com/IBM/fp-go/v2/internal/record"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func MonadTraverseArray[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](tas AAS, f func(A) GB) GBS {
|
func MonadTraverseArray[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](tas AAS, f func(A) GB) GBS {
|
||||||
return RA.MonadTraverse(
|
return RA.MonadTraverse(
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -32,6 +33,7 @@ func MonadTraverseArray[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func MonadTraverseArraySeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](tas AAS, f func(A) GB) GBS {
|
func MonadTraverseArraySeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](tas AAS, f func(A) GB) GBS {
|
||||||
return RA.MonadTraverse(
|
return RA.MonadTraverse(
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -43,6 +45,7 @@ func MonadTraverseArraySeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func MonadTraverseArrayPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](tas AAS, f func(A) GB) GBS {
|
func MonadTraverseArrayPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](tas AAS, f func(A) GB) GBS {
|
||||||
return RA.MonadTraverse(
|
return RA.MonadTraverse(
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -54,6 +57,7 @@ func MonadTraverseArrayPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func TraverseArray[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(A) GB) func(AAS) GBS {
|
func TraverseArray[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(A) GB) func(AAS) GBS {
|
||||||
return RA.Traverse[AAS](
|
return RA.Traverse[AAS](
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -64,6 +68,7 @@ func TraverseArray[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func TraverseArraySeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(A) GB) func(AAS) GBS {
|
func TraverseArraySeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(A) GB) func(AAS) GBS {
|
||||||
return RA.Traverse[AAS](
|
return RA.Traverse[AAS](
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -74,6 +79,7 @@ func TraverseArraySeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B an
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func TraverseArrayPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(A) GB) func(AAS) GBS {
|
func TraverseArrayPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(A) GB) func(AAS) GBS {
|
||||||
return RA.Traverse[AAS](
|
return RA.Traverse[AAS](
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -84,6 +90,7 @@ func TraverseArrayPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B an
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func TraverseArrayWithIndex[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(int, A) GB) func(AAS) GBS {
|
func TraverseArrayWithIndex[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(int, A) GB) func(AAS) GBS {
|
||||||
return RA.TraverseWithIndex[AAS](
|
return RA.TraverseWithIndex[AAS](
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -94,6 +101,7 @@ func TraverseArrayWithIndex[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func TraverseArrayWithIndexSeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(int, A) GB) func(AAS) GBS {
|
func TraverseArrayWithIndexSeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(int, A) GB) func(AAS) GBS {
|
||||||
return RA.TraverseWithIndex[AAS](
|
return RA.TraverseWithIndex[AAS](
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -104,6 +112,7 @@ func TraverseArrayWithIndexSeq[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func TraverseArrayWithIndexPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(int, A) GB) func(AAS) GBS {
|
func TraverseArrayWithIndexPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B, A, B any](f func(int, A) GB) func(AAS) GBS {
|
||||||
return RA.TraverseWithIndex[AAS](
|
return RA.TraverseWithIndex[AAS](
|
||||||
Of[GBS, BBS],
|
Of[GBS, BBS],
|
||||||
@@ -114,19 +123,22 @@ func TraverseArrayWithIndexPar[GB ~func() B, GBS ~func() BBS, AAS ~[]A, BBS ~[]B
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func SequenceArray[GA ~func() A, GAS ~func() AAS, AAS ~[]A, GAAS ~[]GA, A any](tas GAAS) GAS {
|
func SequenceArray[GA ~func() A, GAS ~func() AAS, AAS ~[]A, GAAS ~[]GA, A any](tas GAAS) GAS {
|
||||||
return MonadTraverseArray[GA, GAS](tas, F.Identity[GA])
|
return MonadTraverseArray[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func SequenceArraySeq[GA ~func() A, GAS ~func() AAS, AAS ~[]A, GAAS ~[]GA, A any](tas GAAS) GAS {
|
func SequenceArraySeq[GA ~func() A, GAS ~func() AAS, AAS ~[]A, GAAS ~[]GA, A any](tas GAAS) GAS {
|
||||||
return MonadTraverseArraySeq[GA, GAS](tas, F.Identity[GA])
|
return MonadTraverseArraySeq[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func SequenceArrayPar[GA ~func() A, GAS ~func() AAS, AAS ~[]A, GAAS ~[]GA, A any](tas GAAS) GAS {
|
func SequenceArrayPar[GA ~func() A, GAS ~func() AAS, AAS ~[]A, GAAS ~[]GA, A any](tas GAAS) GAS {
|
||||||
return MonadTraverseArrayPar[GA, GAS](tas, F.Identity[GA])
|
return MonadTraverseArrayPar[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseRecord transforms a record using an IO transform an IO of a record
|
//go:deprecate MonadTraverseRecord transforms a record using an IO transform an IO of a record
|
||||||
func MonadTraverseRecord[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](ma MA, f func(A) GB) GBS {
|
func MonadTraverseRecord[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](ma MA, f func(A) GB) GBS {
|
||||||
return RR.MonadTraverse[MA](
|
return RR.MonadTraverse[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -136,7 +148,7 @@ func MonadTraverseRecord[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecord transforms a record using an IO transform an IO of a record
|
//go:deprecate TraverseRecord transforms a record using an IO transform an IO of a record
|
||||||
func TraverseRecord[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](f func(A) GB) func(MA) GBS {
|
func TraverseRecord[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](f func(A) GB) func(MA) GBS {
|
||||||
return RR.Traverse[MA](
|
return RR.Traverse[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -146,7 +158,7 @@ func TraverseRecord[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K co
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndex transforms a record using an IO transform an IO of a record
|
//go:deprecate TraverseRecordWithIndex transforms a record using an IO transform an IO of a record
|
||||||
func TraverseRecordWithIndex[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~map[K]B, K comparable, A, B any](f func(K, A) GB) func(MA) GBS {
|
func TraverseRecordWithIndex[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~map[K]B, K comparable, A, B any](f func(K, A) GB) func(MA) GBS {
|
||||||
return RR.TraverseWithIndex[MA](
|
return RR.TraverseWithIndex[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -156,11 +168,12 @@ func TraverseRecordWithIndex[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~map[
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func SequenceRecord[GA ~func() A, GAS ~func() AAS, AAS ~map[K]A, GAAS ~map[K]GA, K comparable, A any](tas GAAS) GAS {
|
func SequenceRecord[GA ~func() A, GAS ~func() AAS, AAS ~map[K]A, GAAS ~map[K]GA, K comparable, A any](tas GAAS) GAS {
|
||||||
return MonadTraverseRecord[GAS](tas, F.Identity[GA])
|
return MonadTraverseRecord[GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseRecordSeq transforms a record using an IO transform an IO of a record
|
//go:deprecate MonadTraverseRecordSeq transforms a record using an IO transform an IO of a record
|
||||||
func MonadTraverseRecordSeq[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](ma MA, f func(A) GB) GBS {
|
func MonadTraverseRecordSeq[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](ma MA, f func(A) GB) GBS {
|
||||||
return RR.MonadTraverse[MA](
|
return RR.MonadTraverse[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -170,7 +183,7 @@ func MonadTraverseRecordSeq[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordSeq transforms a record using an IO transform an IO of a record
|
//go:deprecate TraverseRecordSeq transforms a record using an IO transform an IO of a record
|
||||||
func TraverseRecordSeq[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](f func(A) GB) func(MA) GBS {
|
func TraverseRecordSeq[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](f func(A) GB) func(MA) GBS {
|
||||||
return RR.Traverse[MA](
|
return RR.Traverse[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -180,7 +193,7 @@ func TraverseRecordSeq[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndexSeq transforms a record using an IO transform an IO of a record
|
//go:deprecate TraverseRecordWithIndexSeq transforms a record using an IO transform an IO of a record
|
||||||
func TraverseRecordWithIndexSeq[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~map[K]B, K comparable, A, B any](f func(K, A) GB) func(MA) GBS {
|
func TraverseRecordWithIndexSeq[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~map[K]B, K comparable, A, B any](f func(K, A) GB) func(MA) GBS {
|
||||||
return RR.TraverseWithIndex[MA](
|
return RR.TraverseWithIndex[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -190,11 +203,12 @@ func TraverseRecordWithIndexSeq[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~m
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func SequenceRecordSeq[GA ~func() A, GAS ~func() AAS, AAS ~map[K]A, GAAS ~map[K]GA, K comparable, A any](tas GAAS) GAS {
|
func SequenceRecordSeq[GA ~func() A, GAS ~func() AAS, AAS ~map[K]A, GAAS ~map[K]GA, K comparable, A any](tas GAAS) GAS {
|
||||||
return MonadTraverseRecordSeq[GAS](tas, F.Identity[GA])
|
return MonadTraverseRecordSeq[GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseRecordPar transforms a record using an IO transform an IO of a record
|
//go:deprecate MonadTraverseRecordPar transforms a record using an IO transform an IO of a record
|
||||||
func MonadTraverseRecordPar[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](ma MA, f func(A) GB) GBS {
|
func MonadTraverseRecordPar[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](ma MA, f func(A) GB) GBS {
|
||||||
return RR.MonadTraverse[MA](
|
return RR.MonadTraverse[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -204,7 +218,7 @@ func MonadTraverseRecordPar[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordPar transforms a record using an IO transform an IO of a record
|
//go:deprecate TraverseRecordPar transforms a record using an IO transform an IO of a record
|
||||||
func TraverseRecordPar[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](f func(A) GB) func(MA) GBS {
|
func TraverseRecordPar[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K comparable, A, B any](f func(A) GB) func(MA) GBS {
|
||||||
return RR.Traverse[MA](
|
return RR.Traverse[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -214,7 +228,7 @@ func TraverseRecordPar[GBS ~func() MB, MA ~map[K]A, GB ~func() B, MB ~map[K]B, K
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndexPar transforms a record using an IO transform an IO of a record
|
//go:deprecate TraverseRecordWithIndexPar transforms a record using an IO transform an IO of a record
|
||||||
func TraverseRecordWithIndexPar[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~map[K]B, K comparable, A, B any](f func(K, A) GB) func(MA) GBS {
|
func TraverseRecordWithIndexPar[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~map[K]B, K comparable, A, B any](f func(K, A) GB) func(MA) GBS {
|
||||||
return RR.TraverseWithIndex[MA](
|
return RR.TraverseWithIndex[MA](
|
||||||
Of[GBS, MB],
|
Of[GBS, MB],
|
||||||
@@ -224,6 +238,7 @@ func TraverseRecordWithIndexPar[GB ~func() B, GBS ~func() MB, MA ~map[K]A, MB ~m
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:deprecate
|
||||||
func SequenceRecordPar[GA ~func() A, GAS ~func() AAS, AAS ~map[K]A, GAAS ~map[K]GA, K comparable, A any](tas GAAS) GAS {
|
func SequenceRecordPar[GA ~func() A, GAS ~func() AAS, AAS ~map[K]A, GAAS ~map[K]GA, K comparable, A any](tas GAAS) GAS {
|
||||||
return MonadTraverseRecordPar[GAS](tas, F.Identity[GA])
|
return MonadTraverseRecordPar[GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
@@ -121,6 +121,10 @@ func Ap[B, A any](ma IO[A]) func(IO[func(A) B]) IO[B] {
|
|||||||
return F.Bind2nd(MonadAp[A, B], ma)
|
return F.Bind2nd(MonadAp[A, B], ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ApSeq[B, A any](ma IO[A]) func(IO[func(A) B]) IO[B] {
|
||||||
|
return Chain(F.Bind1st(MonadMap[A, B], ma))
|
||||||
|
}
|
||||||
|
|
||||||
func Flatten[A any](mma IO[IO[A]]) IO[A] {
|
func Flatten[A any](mma IO[IO[A]]) IO[A] {
|
||||||
return MonadChain(mma, F.Identity)
|
return MonadChain(mma, F.Identity)
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ func TestChain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAp(t *testing.T) {
|
func TestAp(t *testing.T) {
|
||||||
assert.Equal(t, 2, F.Pipe1(Of(utils.Double), Ap[int, int](Of(1)))())
|
assert.Equal(t, 2, F.Pipe1(Of(utils.Double), Ap[int](Of(1)))())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlatten(t *testing.T) {
|
func TestFlatten(t *testing.T) {
|
||||||
|
@@ -16,8 +16,9 @@
|
|||||||
package io
|
package io
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
F "github.com/IBM/fp-go/v2/function"
|
||||||
INTA "github.com/IBM/fp-go/v2/internal/array"
|
INTA "github.com/IBM/fp-go/v2/internal/array"
|
||||||
G "github.com/IBM/fp-go/v2/io/generic"
|
INTR "github.com/IBM/fp-go/v2/internal/record"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MonadTraverseArray[A, B any](tas []A, f func(A) IO[B]) IO[[]B] {
|
func MonadTraverseArray[A, B any](tas []A, f func(A) IO[B]) IO[[]B] {
|
||||||
@@ -46,73 +47,136 @@ func TraverseArray[A, B any](f func(A) IO[B]) func([]A) IO[[]B] {
|
|||||||
// TraverseArrayWithIndex applies a function returning an [IO] to all elements in an array and the
|
// TraverseArrayWithIndex applies a function returning an [IO] to all elements in an array and the
|
||||||
// transforms this into an [IO] of that array
|
// transforms this into an [IO] of that array
|
||||||
func TraverseArrayWithIndex[A, B any](f func(int, A) IO[B]) func([]A) IO[[]B] {
|
func TraverseArrayWithIndex[A, B any](f func(int, A) IO[B]) func([]A) IO[[]B] {
|
||||||
return G.TraverseArrayWithIndex[IO[B], IO[[]B], []A](f)
|
return INTA.TraverseWithIndex[[]A](
|
||||||
|
Of[[]B],
|
||||||
|
Map[[]B, func(B) []B],
|
||||||
|
Ap[[]B, B],
|
||||||
|
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceArray converts an array of [IO] to an [IO] of an array
|
// SequenceArray converts an array of [IO] to an [IO] of an array
|
||||||
func SequenceArray[A any](tas []IO[A]) IO[[]A] {
|
func SequenceArray[A any](tas []IO[A]) IO[[]A] {
|
||||||
return G.SequenceArray[IO[A], IO[[]A]](tas)
|
return MonadTraverseArray(tas, F.Identity[IO[A]])
|
||||||
}
|
}
|
||||||
|
|
||||||
func MonadTraverseRecord[K comparable, A, B any](tas map[K]A, f func(A) IO[B]) IO[map[K]B] {
|
func MonadTraverseRecord[K comparable, A, B any](tas map[K]A, f func(A) IO[B]) IO[map[K]B] {
|
||||||
return G.MonadTraverseRecord[IO[map[K]B]](tas, f)
|
return INTR.MonadTraverse(
|
||||||
|
Of[map[K]B],
|
||||||
|
Map[map[K]B, func(B) map[K]B],
|
||||||
|
Ap[map[K]B, B],
|
||||||
|
|
||||||
|
tas,
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecord applies a function returning an [IO] to all elements in a record and the
|
// TraverseRecord applies a function returning an [IO] to all elements in a record and the
|
||||||
// transforms this into an [IO] of that record
|
// transforms this into an [IO] of that record
|
||||||
func TraverseRecord[K comparable, A, B any](f func(A) IO[B]) func(map[K]A) IO[map[K]B] {
|
func TraverseRecord[K comparable, A, B any](f func(A) IO[B]) func(map[K]A) IO[map[K]B] {
|
||||||
return G.TraverseRecord[IO[map[K]B], map[K]A, IO[B]](f)
|
return INTR.Traverse[map[K]A](
|
||||||
|
Of[map[K]B],
|
||||||
|
Map[map[K]B, func(B) map[K]B],
|
||||||
|
Ap[map[K]B, B],
|
||||||
|
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndex applies a function returning an [IO] to all elements in a record and the
|
// TraverseRecordWithIndex applies a function returning an [IO] to all elements in a record and the
|
||||||
// transforms this into an [IO] of that record
|
// transforms this into an [IO] of that record
|
||||||
func TraverseRecordWithIndex[K comparable, A, B any](f func(K, A) IO[B]) func(map[K]A) IO[map[K]B] {
|
func TraverseRecordWithIndex[K comparable, A, B any](f func(K, A) IO[B]) func(map[K]A) IO[map[K]B] {
|
||||||
return G.TraverseRecordWithIndex[IO[B], IO[map[K]B], map[K]A](f)
|
return INTR.TraverseWithIndex[map[K]A](
|
||||||
|
Of[map[K]B],
|
||||||
|
Map[map[K]B, func(B) map[K]B],
|
||||||
|
Ap[map[K]B, B],
|
||||||
|
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceRecord converts a record of [IO] to an [IO] of a record
|
// SequenceRecord converts a record of [IO] to an [IO] of a record
|
||||||
func SequenceRecord[K comparable, A any](tas map[K]IO[A]) IO[map[K]A] {
|
func SequenceRecord[K comparable, A any](tas map[K]IO[A]) IO[map[K]A] {
|
||||||
return G.SequenceRecord[IO[A], IO[map[K]A]](tas)
|
return MonadTraverseRecord(tas, F.Identity[IO[A]])
|
||||||
}
|
}
|
||||||
|
|
||||||
func MonadTraverseArraySeq[A, B any](tas []A, f func(A) IO[B]) IO[[]B] {
|
func MonadTraverseArraySeq[A, B any](tas []A, f func(A) IO[B]) IO[[]B] {
|
||||||
return G.MonadTraverseArraySeq[IO[B], IO[[]B]](tas, f)
|
return INTA.MonadTraverse(
|
||||||
|
Of[[]B],
|
||||||
|
Map[[]B, func(B) []B],
|
||||||
|
ApSeq[[]B, B],
|
||||||
|
|
||||||
|
tas,
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArraySeq applies a function returning an [IO] to all elements in an array and the
|
// TraverseArraySeq applies a function returning an [IO] to all elements in an array and the
|
||||||
// transforms this into an [IO] of that array
|
// transforms this into an [IO] of that array
|
||||||
func TraverseArraySeq[A, B any](f func(A) IO[B]) func([]A) IO[[]B] {
|
func TraverseArraySeq[A, B any](f func(A) IO[B]) func([]A) IO[[]B] {
|
||||||
return G.TraverseArraySeq[IO[B], IO[[]B], []A](f)
|
return INTA.Traverse[[]A](
|
||||||
|
Of[[]B],
|
||||||
|
Map[[]B, func(B) []B],
|
||||||
|
ApSeq[[]B, B],
|
||||||
|
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArrayWithIndexSeq applies a function returning an [IO] to all elements in an array and the
|
// TraverseArrayWithIndexSeq applies a function returning an [IO] to all elements in an array and the
|
||||||
// transforms this into an [IO] of that array
|
// transforms this into an [IO] of that array
|
||||||
func TraverseArrayWithIndexSeq[A, B any](f func(int, A) IO[B]) func([]A) IO[[]B] {
|
func TraverseArrayWithIndexSeq[A, B any](f func(int, A) IO[B]) func([]A) IO[[]B] {
|
||||||
return G.TraverseArrayWithIndexSeq[IO[B], IO[[]B], []A](f)
|
return INTA.TraverseWithIndex[[]A](
|
||||||
|
Of[[]B],
|
||||||
|
Map[[]B, func(B) []B],
|
||||||
|
ApSeq[[]B, B],
|
||||||
|
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceArraySeq converts an array of [IO] to an [IO] of an array
|
// SequenceArraySeq converts an array of [IO] to an [IO] of an array
|
||||||
func SequenceArraySeq[A any](tas []IO[A]) IO[[]A] {
|
func SequenceArraySeq[A any](tas []IO[A]) IO[[]A] {
|
||||||
return G.SequenceArraySeq[IO[A], IO[[]A]](tas)
|
return MonadTraverseArraySeq(tas, F.Identity[IO[A]])
|
||||||
}
|
}
|
||||||
|
|
||||||
func MonadTraverseRecordSeq[K comparable, A, B any](tas map[K]A, f func(A) IO[B]) IO[map[K]B] {
|
func MonadTraverseRecordSeq[K comparable, A, B any](tas map[K]A, f func(A) IO[B]) IO[map[K]B] {
|
||||||
return G.MonadTraverseRecordSeq[IO[map[K]B]](tas, f)
|
return INTR.MonadTraverse(
|
||||||
|
Of[map[K]B],
|
||||||
|
Map[map[K]B, func(B) map[K]B],
|
||||||
|
ApSeq[map[K]B, B],
|
||||||
|
|
||||||
|
tas,
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecord applies a function returning an [IO] to all elements in a record and the
|
// TraverseRecord applies a function returning an [IO] to all elements in a record and the
|
||||||
// transforms this into an [IO] of that record
|
// transforms this into an [IO] of that record
|
||||||
func TraverseRecordSeq[K comparable, A, B any](f func(A) IO[B]) func(map[K]A) IO[map[K]B] {
|
func TraverseRecordSeq[K comparable, A, B any](f func(A) IO[B]) func(map[K]A) IO[map[K]B] {
|
||||||
return G.TraverseRecordSeq[IO[map[K]B], map[K]A, IO[B]](f)
|
return INTR.Traverse[map[K]A](
|
||||||
|
Of[map[K]B],
|
||||||
|
Map[map[K]B, func(B) map[K]B],
|
||||||
|
ApSeq[map[K]B, B],
|
||||||
|
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndexSeq applies a function returning an [IO] to all elements in a record and the
|
// TraverseRecordWithIndexSeq applies a function returning an [IO] to all elements in a record and the
|
||||||
// transforms this into an [IO] of that record
|
// transforms this into an [IO] of that record
|
||||||
func TraverseRecordWithIndeSeq[K comparable, A, B any](f func(K, A) IO[B]) func(map[K]A) IO[map[K]B] {
|
func TraverseRecordWithIndeSeq[K comparable, A, B any](f func(K, A) IO[B]) func(map[K]A) IO[map[K]B] {
|
||||||
return G.TraverseRecordWithIndexSeq[IO[B], IO[map[K]B], map[K]A](f)
|
return INTR.TraverseWithIndex[map[K]A](
|
||||||
|
Of[map[K]B],
|
||||||
|
Map[map[K]B, func(B) map[K]B],
|
||||||
|
ApSeq[map[K]B, B],
|
||||||
|
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceRecordSeq converts a record of [IO] to an [IO] of a record
|
// SequenceRecordSeq converts a record of [IO] to an [IO] of a record
|
||||||
func SequenceRecordSeq[K comparable, A any](tas map[K]IO[A]) IO[map[K]A] {
|
func SequenceRecordSeq[K comparable, A any](tas map[K]IO[A]) IO[map[K]A] {
|
||||||
return G.SequenceRecordSeq[IO[A], IO[map[K]A]](tas)
|
return MonadTraverseRecordSeq(tas, F.Identity[IO[A]])
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user