1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-24 19:29:11 +02:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Carsten Leue
c629d18bb3 Merge pull request #66 from IBM/cleue-add-try-catch-for-single-value-return
fix: remove File.GetName and add Join for convenience
2023-10-11 21:25:17 +02:00
Dr. Carsten Leue
1eefc28ba6 fix: remove File.GetName and add Join for convenience
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-10-11 17:36:11 +02:00
Carsten Leue
af2915d98a Merge pull request #65 from IBM/cleue-fix-flap-order
fix: change order of generics for flap
2023-10-10 22:41:43 +02:00
Dr. Carsten Leue
e9f9c2777f fix: change order of generics for flap
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-10-10 22:40:59 +02:00
Carsten Leue
895862a67e Merge pull request #64 from IBM/cleue-add-FromReaderIO
fix: add missing RightReaderIO and FromReaderIO to context
2023-10-10 15:05:34 +02:00
Dr. Carsten Leue
caf0574742 fix: add missing RightReaderIO and FromReaderIO to context
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-10-10 15:04:59 +02:00
Carsten Leue
bace6f01eb Merge pull request #62 from IBM/cleue-add-missing-chain-readeriok
fix: add missing ChainReaderIOK
2023-10-06 23:03:16 +02:00
Dr. Carsten Leue
254c63a16f fix: add missing ChainReaderIOK
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-10-06 23:02:45 +02:00
Carsten Leue
655c8a9b1d Merge pull request #61 from IBM/cleue-add-chain-first-to-readerio
fix: add missing ChainXXIOK to Reader
2023-10-06 22:36:38 +02:00
11 changed files with 132 additions and 19 deletions

View File

@@ -309,10 +309,10 @@ func Push[A any](a A) func([]A) []A {
return G.Push[[]A](a)
}
func MonadFlap[A, B any](fab []func(A) B, a A) []B {
func MonadFlap[B, A any](fab []func(A) B, a A) []B {
return G.MonadFlap[func(A) B, []func(A) B, []B, A, B](fab, a)
}
func Flap[A, B any](a A) func([]func(A) B) []B {
func Flap[B, A any](a A) func([]func(A) B) []B {
return G.Flap[func(A) B, []func(A) B, []B, A, B](a)
}

View File

@@ -19,7 +19,6 @@ import (
"os"
RIOE "github.com/IBM/fp-go/context/readerioeither"
FL "github.com/IBM/fp-go/file"
F "github.com/IBM/fp-go/function"
IO "github.com/IBM/fp-go/io"
IOF "github.com/IBM/fp-go/io/file"
@@ -32,7 +31,7 @@ var (
// destroy handler
onReleaseTempFile = F.Flow4(
IOF.Close[*os.File],
IO.Map(FL.GetName),
IO.Map((*os.File).Name),
RIOE.FromIO[string],
RIOE.Chain(Remove),
)

View File

@@ -480,6 +480,34 @@ func ChainIOK[
return RIE.ChainIOK[GRA, GRB](f)
}
func MonadChainReaderIOK[
GRB ~func(context.Context) GIOB,
GRA ~func(context.Context) GIOA,
GRIO ~func(context.Context) GIO,
GIOA ~func() E.Either[error, A],
GIOB ~func() E.Either[error, B],
GIO ~func() B,
A, B any](ma GRA, f func(A) GRIO) GRB {
return RIE.MonadChainReaderIOK[GRA, GRB](ma, f)
}
func ChainReaderIOK[
GRB ~func(context.Context) GIOB,
GRA ~func(context.Context) GIOA,
GRIO ~func(context.Context) GIO,
GIOA ~func() E.Either[error, A],
GIOB ~func() E.Either[error, B],
GIO ~func() B,
A, B any](f func(A) GRIO) func(ma GRA) GRB {
return RIE.ChainReaderIOK[GRA, GRB](f)
}
func MonadChainFirstIOK[
GRA ~func(context.Context) GIOA,
GIOA ~func() E.Either[error, A],
@@ -592,3 +620,47 @@ func Flatten[
A any](rdr GGRA) GRA {
return RIE.Flatten[GRA](rdr)
}
func MonadFromReaderIO[
GRIOEA ~func(context.Context) GIOEA,
GIOEA ~func() E.Either[error, A],
GRIOA ~func(context.Context) GIOA,
GIOA ~func() A,
A any](a A, f func(A) GRIOA) GRIOEA {
return RIE.MonadFromReaderIO[GRIOEA](a, f)
}
func FromReaderIO[
GRIOEA ~func(context.Context) GIOEA,
GIOEA ~func() E.Either[error, A],
GRIOA ~func(context.Context) GIOA,
GIOA ~func() A,
A any](f func(A) GRIOA) func(A) GRIOEA {
return RIE.FromReaderIO[GRIOEA](f)
}
func RightReaderIO[
GRIOEA ~func(context.Context) GIOEA,
GIOEA ~func() E.Either[error, A],
GRIOA ~func(context.Context) GIOA,
GIOA ~func() A,
A any](ma GRIOA) GRIOEA {
return RIE.RightReaderIO[GRIOEA](ma)
}
func LeftReaderIO[
GRIOEA ~func(context.Context) GIOEA,
GIOEA ~func() E.Either[error, A],
GRIOE ~func(context.Context) GIOE,
GIOE ~func() error,
A any](ma GRIOE) GRIOEA {
return RIE.LeftReaderIO[GRIOEA](ma)
}

View File

@@ -164,6 +164,14 @@ func Never[A any]() ReaderIOEither[A] {
return G.Never[ReaderIOEither[A]]()
}
func MonadChainReaderIOK[A, B any](ma ReaderIOEither[A], f func(A) RIO.ReaderIO[B]) ReaderIOEither[B] {
return G.MonadChainReaderIOK[ReaderIOEither[B], ReaderIOEither[A]](ma, f)
}
func ChainReaderIOK[A, B any](f func(A) RIO.ReaderIO[B]) func(ma ReaderIOEither[A]) ReaderIOEither[B] {
return G.ChainReaderIOK[ReaderIOEither[B], ReaderIOEither[A]](f)
}
func MonadChainIOK[A, B any](ma ReaderIOEither[A], f func(A) IO.IO[B]) ReaderIOEither[B] {
return G.MonadChainIOK[ReaderIOEither[B], ReaderIOEither[A]](ma, f)
}
@@ -226,3 +234,19 @@ func Flatten[
A any](rdr ReaderIOEither[ReaderIOEither[A]]) ReaderIOEither[A] {
return G.Flatten[ReaderIOEither[ReaderIOEither[A]]](rdr)
}
func MonadFromReaderIO[A any](a A, f func(A) RIO.ReaderIO[A]) ReaderIOEither[A] {
return G.MonadFromReaderIO[ReaderIOEither[A]](a, f)
}
func FromReaderIO[A any](f func(A) RIO.ReaderIO[A]) func(A) ReaderIOEither[A] {
return G.FromReaderIO[ReaderIOEither[A]](f)
}
func RightReaderIO[A any](ma RIO.ReaderIO[A]) ReaderIOEither[A] {
return G.RightReaderIO[ReaderIOEither[A]](ma)
}
func LeftReaderIO[A any](ma RIO.ReaderIO[error]) ReaderIOEither[A] {
return G.LeftReaderIO[ReaderIOEither[A]](ma)
}

View File

@@ -248,12 +248,12 @@ func Swap[E, A any](val Either[E, A]) Either[A, E] {
return MonadFold(val, Right[A, E], Left[E, A])
}
func MonadFlap[E, A, B any](fab Either[E, func(A) B], a A) Either[E, B] {
func MonadFlap[E, B, A any](fab Either[E, func(A) B], a A) Either[E, B] {
return FC.MonadFlap(MonadMap[E, func(A) B, B], fab, a)
}
func Flap[E, A, B any](a A) func(Either[E, func(A) B]) Either[E, B] {
return F.Bind2nd(MonadFlap[E, A, B], a)
func Flap[E, B, A any](a A) func(Either[E, func(A) B]) Either[E, B] {
return F.Bind2nd(MonadFlap[E, B, A], a)
}
func MonadAlt[E, A any](fa Either[E, A], that L.Lazy[Either[E, A]]) Either[E, A] {

View File

@@ -15,9 +15,11 @@
package file
import "os"
import "path/filepath"
// GetName is the getter for the `Name` property of [os.File]
func GetName(f *os.File) string {
return f.Name()
// Join appends a filename to a root path
func Join(name string) func(root string) string {
return func(root string) string {
return filepath.Join(root, name)
}
}

View File

@@ -64,10 +64,10 @@ func ChainFirst[A, B any](f func(A) B) func(A) A {
return G.ChainFirst(f)
}
func MonadFlap[A, B any](fab func(A) B, a A) B {
func MonadFlap[B, A any](fab func(A) B, a A) B {
return G.MonadFlap[func(A) B](fab, a)
}
func Flap[A, B any](a A) func(func(A) B) B {
func Flap[B, A any](a A) func(func(A) B) B {
return G.Flap[func(A) B](a)
}

View File

@@ -139,7 +139,7 @@ func Defer[A any](gen func() IO[A]) IO[A] {
return G.Defer[IO[A]](gen)
}
func MonadFlap[A, B any](fab IO[func(A) B], a A) IO[B] {
func MonadFlap[B, A any](fab IO[func(A) B], a A) IO[B] {
return G.MonadFlap[func(A) B, IO[func(A) B], IO[B], A, B](fab, a)
}

View File

@@ -18,7 +18,6 @@ package file
import (
"os"
FL "github.com/IBM/fp-go/file"
F "github.com/IBM/fp-go/function"
IO "github.com/IBM/fp-go/io"
IOF "github.com/IBM/fp-go/io/file"
@@ -33,7 +32,7 @@ var (
// destroy handler
onReleaseTempFile = F.Flow4(
IOF.Close[*os.File],
IO.Map(FL.GetName),
IO.Map((*os.File).Name),
IOE.FromIO[error, string],
IOE.Chain(Remove),
)

View File

@@ -147,10 +147,10 @@ func Filter[A any](pred func(A) bool) func(Option[A]) Option[A] {
return Fold(None[A], F.Ternary(pred, Of[A], F.Ignore1of1[A](None[A])))
}
func MonadFlap[A, B any](fab Option[func(A) B], a A) Option[B] {
func MonadFlap[B, A any](fab Option[func(A) B], a A) Option[B] {
return FC.MonadFlap(MonadMap[func(A) B, B], fab, a)
}
func Flap[A, B any](a A) func(Option[func(A) B]) Option[B] {
return F.Bind2nd(MonadFlap[A, B], a)
func Flap[B, A any](a A) func(Option[func(A) B]) Option[B] {
return F.Bind2nd(MonadFlap[B, A], a)
}

View File

@@ -147,6 +147,23 @@ func ChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E
)
}
func MonadChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() ET.Either[E, A], GIOEB ~func() ET.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](ma GEA, f func(A) GB) GEB {
return FR.MonadChainReaderK(
MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B],
RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B],
ma,
f,
)
}
func ChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() ET.Either[E, A], GIOEB ~func() ET.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](f func(A) GB) func(GEA) GEB {
return FR.ChainReaderK(
MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B],
RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B],
f,
)
}
func MonadChainIOEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](ma GEA, f func(A) GIOB) GEB {
return FIOE.MonadChainIOEitherK(
MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B],