Skip to content

Commit

Permalink
fix: add missing Fold to ReaderIOEither
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
  • Loading branch information
CarstenLeue committed May 24, 2024
1 parent 9c7a5bb commit e39e5e0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions context/readerioeither/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
IOE "github.com/IBM/fp-go/ioeither"
L "github.com/IBM/fp-go/lazy"
O "github.com/IBM/fp-go/option"
RIO "github.com/IBM/fp-go/readerio"
)

func FromEither[A any](e ET.Either[error, A]) ReaderIOEither[A] {
Expand Down Expand Up @@ -192,8 +193,7 @@ func Memoize[A any](rdr ReaderIOEither[A]) ReaderIOEither[A] {
}

// Flatten converts a nested [ReaderIOEither] into a [ReaderIOEither]
func Flatten[
A any](rdr ReaderIOEither[ReaderIOEither[A]]) ReaderIOEither[A] {
func Flatten[A any](rdr ReaderIOEither[ReaderIOEither[A]]) ReaderIOEither[A] {
return G.Flatten[ReaderIOEither[ReaderIOEither[A]]](rdr)
}

Expand All @@ -204,3 +204,15 @@ func MonadFlap[B, A any](fab ReaderIOEither[func(A) B], a A) ReaderIOEither[B] {
func Flap[B, A any](a A) func(ReaderIOEither[func(A) B]) ReaderIOEither[B] {
return G.Flap[ReaderIOEither[func(A) B], ReaderIOEither[B]](a)
}

func Fold[A, B any](onLeft func(error) ReaderIOEither[B], onRight func(A) ReaderIOEither[B]) func(ReaderIOEither[A]) ReaderIOEither[B] {
return G.Fold[ReaderIOEither[B], ReaderIOEither[A]](onLeft, onRight)
}

func GetOrElse[A any](onLeft func(error) RIO.ReaderIO[context.Context, A]) func(ReaderIOEither[A]) RIO.ReaderIO[context.Context, A] {
return G.GetOrElse[RIO.ReaderIO[context.Context, A], ReaderIOEither[A]](onLeft)
}

func OrLeft[A any](onLeft func(error) RIO.ReaderIO[context.Context, error]) func(ReaderIOEither[A]) ReaderIOEither[A] {
return G.OrLeft[ReaderIOEither[A]](onLeft)
}

0 comments on commit e39e5e0

Please sign in to comment.