mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: break cyclic dependencies between IOOption and IOEither (#83)
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -117,7 +117,7 @@ var (
|
|||||||
mp,
|
mp,
|
||||||
R.Map[int](F.Flow3(
|
R.Map[int](F.Flow3(
|
||||||
getAt(res),
|
getAt(res),
|
||||||
IOO.FromIOEither[error, any],
|
IOE.ToIOOption[error, any],
|
||||||
F.ToAny[IOO.IOOption[any]],
|
F.ToAny[IOO.IOOption[any]],
|
||||||
)),
|
)),
|
||||||
IOE.Of[error, paramValue],
|
IOE.Of[error, paramValue],
|
||||||
|
@@ -336,3 +336,14 @@ func MonadFlap[GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B]
|
|||||||
func Flap[GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], E, B, A any](a A) func(GEAB) GEB {
|
func Flap[GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], E, B, A any](a A) func(GEAB) GEB {
|
||||||
return FC.Flap(MonadMap[GEAB, GEB], a)
|
return FC.Flap(MonadMap[GEAB, GEB], a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToIOOption[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 FromIOOption[GEA ~func() ET.Either[E, A], GA ~func() O.Option[A], E, A any](onNone func() E) func(ioo GA) GEA {
|
||||||
|
return IO.Map[GA, GEA](ET.FromOption[A](onNone))
|
||||||
|
}
|
||||||
|
@@ -19,6 +19,7 @@ import (
|
|||||||
ET "github.com/IBM/fp-go/either"
|
ET "github.com/IBM/fp-go/either"
|
||||||
I "github.com/IBM/fp-go/io"
|
I "github.com/IBM/fp-go/io"
|
||||||
G "github.com/IBM/fp-go/ioeither/generic"
|
G "github.com/IBM/fp-go/ioeither/generic"
|
||||||
|
IOO "github.com/IBM/fp-go/iooption"
|
||||||
L "github.com/IBM/fp-go/lazy"
|
L "github.com/IBM/fp-go/lazy"
|
||||||
O "github.com/IBM/fp-go/option"
|
O "github.com/IBM/fp-go/option"
|
||||||
)
|
)
|
||||||
@@ -63,6 +64,10 @@ func FromOption[A, E any](onNone func() E) func(o O.Option[A]) IOEither[E, A] {
|
|||||||
return G.FromOption[IOEither[E, A]](onNone)
|
return G.FromOption[IOEither[E, A]](onNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FromIOOption[A, E any](onNone func() E) func(o IOO.IOOption[A]) IOEither[E, A] {
|
||||||
|
return G.FromIOOption[IOEither[E, A], IOO.IOOption[A]](onNone)
|
||||||
|
}
|
||||||
|
|
||||||
func ChainOptionK[A, B, E any](onNone func() E) func(func(A) O.Option[B]) func(IOEither[E, A]) IOEither[E, B] {
|
func ChainOptionK[A, B, E any](onNone func() E) func(func(A) O.Option[B]) func(IOEither[E, A]) IOEither[E, B] {
|
||||||
return G.ChainOptionK[IOEither[E, A], IOEither[E, B]](onNone)
|
return G.ChainOptionK[IOEither[E, A], IOEither[E, B]](onNone)
|
||||||
}
|
}
|
||||||
@@ -266,3 +271,8 @@ func MonadFlap[E, B, A any](fab IOEither[E, func(A) B], a A) IOEither[E, B] {
|
|||||||
func Flap[E, B, A any](a A) func(IOEither[E, func(A) B]) IOEither[E, B] {
|
func Flap[E, B, A any](a A) func(IOEither[E, func(A) B]) IOEither[E, B] {
|
||||||
return G.Flap[IOEither[E, func(A) B], IOEither[E, B]](a)
|
return G.Flap[IOEither[E, func(A) B], IOEither[E, B]](a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToIOOption converts an [IOEither] to an [IOO.IOOption]
|
||||||
|
func ToIOOption[E, A any](ioe IOEither[E, A]) IOO.IOOption[A] {
|
||||||
|
return G.ToIOOption[IOO.IOOption[A]](ioe)
|
||||||
|
}
|
||||||
|
@@ -64,13 +64,6 @@ func FromEither[GA ~func() O.Option[A], E, A any](e ET.Either[E, A]) 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 {
|
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)
|
return optiont.MonadMap(IO.MonadMap[GA, GB, O.Option[A], O.Option[B]], fa, f)
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,6 @@ package iooption
|
|||||||
import (
|
import (
|
||||||
ET "github.com/IBM/fp-go/either"
|
ET "github.com/IBM/fp-go/either"
|
||||||
I "github.com/IBM/fp-go/io"
|
I "github.com/IBM/fp-go/io"
|
||||||
IOE "github.com/IBM/fp-go/ioeither"
|
|
||||||
G "github.com/IBM/fp-go/iooption/generic"
|
G "github.com/IBM/fp-go/iooption/generic"
|
||||||
O "github.com/IBM/fp-go/option"
|
O "github.com/IBM/fp-go/option"
|
||||||
)
|
)
|
||||||
@@ -129,11 +128,6 @@ func Defer[A any](gen func() IOOption[A]) IOOption[A] {
|
|||||||
return G.Defer[IOOption[A]](gen)
|
return G.Defer[IOOption[A]](gen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromIOEither converts an [IOEither] into an [IOOption]
|
|
||||||
func FromIOEither[E, A any](ioe IOE.IOEither[E, A]) IOOption[A] {
|
|
||||||
return G.FromIOEither[IOOption[A]](ioe)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FromEither converts an [Either] into an [IOOption]
|
// FromEither converts an [Either] into an [IOOption]
|
||||||
func FromEither[E, A any](e ET.Either[E, A]) IOOption[A] {
|
func FromEither[E, A any](e ET.Either[E, A]) IOOption[A] {
|
||||||
return G.FromEither[IOOption[A]](e)
|
return G.FromEither[IOOption[A]](e)
|
||||||
|
@@ -52,7 +52,7 @@ func TestIOEitherToOption2(t *testing.T) {
|
|||||||
content,
|
content,
|
||||||
IOEF.WriteFile(filepath.Join(tmpDir, "test.txt"), os.ModePerm),
|
IOEF.WriteFile(filepath.Join(tmpDir, "test.txt"), os.ModePerm),
|
||||||
IOE.Swap[error, []byte],
|
IOE.Swap[error, []byte],
|
||||||
IOO.FromIOEither[[]byte, error],
|
IOE.ToIOOption[[]byte, error],
|
||||||
)
|
)
|
||||||
|
|
||||||
fmt.Println(resIOO())
|
fmt.Println(resIOO())
|
||||||
|
Reference in New Issue
Block a user