1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-10 22:31:32 +02:00

fix: migrate MonadTraverseArray and TraverseArray

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2025-03-02 11:08:09 +01:00
parent eb4218c575
commit b53ae32570

View File

@@ -16,17 +16,31 @@
package io package io
import ( import (
INTA "github.com/IBM/fp-go/v2/internal/array"
G "github.com/IBM/fp-go/v2/io/generic" G "github.com/IBM/fp-go/v2/io/generic"
) )
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] {
return G.MonadTraverseArray[IO[B], IO[[]B]](tas, f) return INTA.MonadTraverse(
Of[[]B],
Map[[]B, func(B) []B],
Ap[[]B, B],
tas,
f,
)
} }
// TraverseArray applies a function returning an [IO] to all elements in an array and the // TraverseArray 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 TraverseArray[A, B any](f func(A) IO[B]) func([]A) IO[[]B] { func TraverseArray[A, B any](f func(A) IO[B]) func([]A) IO[[]B] {
return G.TraverseArray[IO[B], IO[[]B], []A](f) return INTA.Traverse[[]A](
Of[[]B],
Map[[]B, func(B) []B],
Ap[[]B, B],
f,
)
} }
// 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