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

fix: add missing IOO.FromIOEither

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-09-19 12:24:05 +02:00
parent dc894ad643
commit 7c12b72db1
6 changed files with 234 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ package generic
import (
"time"
ET "github.com/IBM/fp-go/either"
F "github.com/IBM/fp-go/function"
FI "github.com/IBM/fp-go/internal/fromio"
"github.com/IBM/fp-go/internal/optiont"
@@ -55,6 +56,21 @@ func FromOption[GA ~func() O.Option[A], A any](o O.Option[A]) GA {
return IO.Of[GA](o)
}
func FromEither[GA ~func() O.Option[A], E, A any](e ET.Either[E, A]) GA {
return F.Pipe2(
e,
ET.ToOption[E, A],
FromOption[GA],
)
}
func FromIOEither[GA ~func() O.Option[A], GEA ~func() ET.Either[E, A], E, A any](ioe GEA) GA {
return F.Pipe1(
ioe,
IO.Map[GEA, GA](ET.ToOption[E, A]),
)
}
func MonadMap[GA ~func() O.Option[A], GB ~func() O.Option[B], A, B any](fa GA, f func(A) B) GB {
return optiont.MonadMap(IO.MonadMap[GA, GB, O.Option[A], O.Option[B]], fa, f)
}