1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-07-15 01:24:23 +02:00

fix: refactorY

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2025-03-03 12:24:35 +01:00
parent 24a7cae6e9
commit 8a4ecd2203
19 changed files with 732 additions and 829 deletions

View File

@ -16,8 +16,9 @@
package ioeither
import (
ET "github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/ioeither/generic"
"github.com/IBM/fp-go/v2/either"
BR "github.com/IBM/fp-go/v2/internal/bracket"
"github.com/IBM/fp-go/v2/io"
)
// Bracket makes sure that a resource is cleaned up in the event of an error. The release action is called regardless of
@ -25,7 +26,16 @@ import (
func Bracket[E, A, B, ANY any](
acquire IOEither[E, A],
use func(A) IOEither[E, B],
release func(A, ET.Either[E, B]) IOEither[E, ANY],
release func(A, either.Either[E, B]) IOEither[E, ANY],
) IOEither[E, B] {
return G.Bracket(acquire, use, release)
return BR.Bracket[IOEither[E, A], IOEither[E, B], IOEither[E, ANY], either.Either[E, B], A, B](
io.Of[either.Either[E, B]],
MonadChain[E, A, B],
io.MonadChain[either.Either[E, B], either.Either[E, B]],
MonadChain[E, ANY, B],
acquire,
use,
release,
)
}

View File

@ -16,17 +16,17 @@
package ioeither
import (
ET "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/either"
EQ "github.com/IBM/fp-go/v2/eq"
IO "github.com/IBM/fp-go/v2/io"
)
// Eq implements the equals predicate for values contained in the IOEither monad
func Eq[E, A any](eq EQ.Eq[ET.Either[E, A]]) EQ.Eq[IOEither[E, A]] {
func Eq[E, A any](eq EQ.Eq[either.Either[E, A]]) EQ.Eq[IOEither[E, A]] {
return IO.Eq(eq)
}
// FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function
func FromStrictEquals[E, A comparable]() EQ.Eq[IOEither[E, A]] {
return Eq(ET.FromStrictEquals[E, A]())
return Eq(either.FromStrictEquals[E, A]())
}

View File

@ -16,13 +16,21 @@
package exec
import (
"context"
"github.com/IBM/fp-go/v2/exec"
F "github.com/IBM/fp-go/v2/function"
IOE "github.com/IBM/fp-go/v2/ioeither"
G "github.com/IBM/fp-go/v2/ioeither/generic"
INTE "github.com/IBM/fp-go/v2/internal/exec"
"github.com/IBM/fp-go/v2/ioeither"
)
var (
// Command executes a command
Command = F.Curry3(G.Command[IOE.IOEither[error, exec.CommandOutput]])
Command = F.Curry3(command)
)
func command(name string, args []string, in []byte) ioeither.IOEither[error, exec.CommandOutput] {
return ioeither.TryCatchError(func() (exec.CommandOutput, error) {
return INTE.Exec(context.Background(), name, args, in)
})
}

View File

@ -24,7 +24,7 @@ import (
E "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/exec"
F "github.com/IBM/fp-go/v2/function"
IOE "github.com/IBM/fp-go/v2/ioeither"
"github.com/IBM/fp-go/v2/ioeither"
"github.com/stretchr/testify/assert"
)
@ -32,7 +32,7 @@ func TestOpenSSL(t *testing.T) {
// execute the openSSL binary
version := F.Pipe1(
Command("openssl")(RA.From("version"))(B.Monoid.Empty()),
IOE.Map[error](F.Flow3(
ioeither.Map[error](F.Flow3(
exec.StdOut,
B.ToString,
strings.TrimSpace,

View File

@ -16,12 +16,12 @@
package generic
import (
ET "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/internal/apply"
)
// MonadApFirst combines two effectful actions, keeping only the result of the first.
func MonadApFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GBA ~func() ET.Either[E, func(B) A], E, A, B any](first GA, second GB) GA {
func MonadApFirst[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBA ~func() either.Either[E, func(B) A], E, A, B any](first GA, second GB) GA {
return G.MonadApFirst(
MonadAp[GA, GBA, GB],
MonadMap[GA, GBA, E, A, func(B) A],
@ -32,7 +32,7 @@ func MonadApFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GBA ~f
}
// ApFirst combines two effectful actions, keeping only the result of the first.
func ApFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GBA ~func() ET.Either[E, func(B) A], E, A, B any](second GB) func(GA) GA {
func ApFirst[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBA ~func() either.Either[E, func(B) A], E, A, B any](second GB) func(GA) GA {
return G.ApFirst(
MonadAp[GA, GBA, GB],
MonadMap[GA, GBA, E, A, func(B) A],
@ -42,7 +42,7 @@ func ApFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GBA ~func()
}
// MonadApSecond combines two effectful actions, keeping only the result of the second.
func MonadApSecond[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GBB ~func() ET.Either[E, func(B) B], E, A, B any](first GA, second GB) GB {
func MonadApSecond[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBB ~func() either.Either[E, func(B) B], E, A, B any](first GA, second GB) GB {
return G.MonadApSecond(
MonadAp[GB, GBB, GB],
MonadMap[GA, GBB, E, A, func(B) B],
@ -53,7 +53,7 @@ func MonadApSecond[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GBB ~
}
// ApSecond combines two effectful actions, keeping only the result of the second.
func ApSecond[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GBB ~func() ET.Either[E, func(B) B], E, A, B any](second GB) func(GA) GB {
func ApSecond[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBB ~func() either.Either[E, func(B) B], E, A, B any](second GB) func(GA) GB {
return G.ApSecond(
MonadAp[GB, GBB, GB],
MonadMap[GA, GBB, E, A, func(B) B],

View File

@ -16,21 +16,21 @@
package generic
import (
ET "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/either"
A "github.com/IBM/fp-go/v2/internal/apply"
C "github.com/IBM/fp-go/v2/internal/chain"
F "github.com/IBM/fp-go/v2/internal/functor"
)
// Bind creates an empty context of type [S] to be used with the [Bind] operation
func Do[GS ~func() ET.Either[E, S], E, S any](
func Do[GS ~func() either.Either[E, S], E, S any](
empty S,
) GS {
return Of[GS, E, S](empty)
}
// Bind attaches the result of a computation to a context [S1] to produce a context [S2]
func Bind[GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], GT ~func() ET.Either[E, T], E, S1, S2, T any](
func Bind[GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], GT ~func() either.Either[E, T], E, S1, S2, T any](
setter func(T) func(S1) S2,
f func(S1) GT,
) func(GS1) GS2 {
@ -43,7 +43,7 @@ func Bind[GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], GT ~func()
}
// Let attaches the result of a computation to a context [S1] to produce a context [S2]
func Let[GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], E, S1, S2, T any](
func Let[GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], E, S1, S2, T any](
key func(T) func(S1) S2,
f func(S1) T,
) func(GS1) GS2 {
@ -55,7 +55,7 @@ func Let[GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], E, S1, S2,
}
// LetTo attaches the a value to a context [S1] to produce a context [S2]
func LetTo[GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], E, S1, S2, B any](
func LetTo[GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], E, S1, S2, B any](
key func(B) func(S1) S2,
b B,
) func(GS1) GS2 {
@ -67,7 +67,7 @@ func LetTo[GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], E, S1, S2
}
// BindTo initializes a new state [S1] from a value [T]
func BindTo[GS1 ~func() ET.Either[E, S1], GT ~func() ET.Either[E, T], E, S1, S2, T any](
func BindTo[GS1 ~func() either.Either[E, S1], GT ~func() either.Either[E, T], E, S1, S2, T any](
setter func(T) S1,
) func(GT) GS1 {
return C.BindTo(
@ -77,13 +77,13 @@ func BindTo[GS1 ~func() ET.Either[E, S1], GT ~func() ET.Either[E, T], E, S1, S2,
}
// ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently
func ApS[GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], GT ~func() ET.Either[E, T], E, S1, S2, T any](
func ApS[GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], GT ~func() either.Either[E, T], E, S1, S2, T any](
setter func(T) func(S1) S2,
fa GT,
) func(GS1) GS2 {
return A.ApS(
Ap[GS2, func() ET.Either[E, func(T) S2], GT, E, T, S2],
Map[GS1, func() ET.Either[E, func(T) S2], E, S1, func(T) S2],
Ap[GS2, func() either.Either[E, func(T) S2], GT, E, T, S2],
Map[GS1, func() either.Either[E, func(T) S2], E, S1, func(T) S2],
setter,
fa,
)

View File

@ -1,46 +0,0 @@
// Copyright (c) 2023 IBM Corp.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package generic
import (
ET "github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/internal/bracket"
I "github.com/IBM/fp-go/v2/io/generic"
)
// Bracket makes sure that a resource is cleaned up in the event of an error. The release action is called regardless of
// whether the body action returns and error or not.
func Bracket[
GA ~func() ET.Either[E, A],
GB ~func() ET.Either[E, B],
GANY ~func() ET.Either[E, ANY],
E, A, B, ANY any](
acquire GA,
use func(A) GB,
release func(A, ET.Either[E, B]) GANY,
) GB {
return G.Bracket[GA, GB, GANY, ET.Either[E, B], A, B](
I.Of[GB, ET.Either[E, B]],
MonadChain[GA, GB, E, A, B],
I.MonadChain[GB, GB, ET.Either[E, B], ET.Either[E, B]],
MonadChain[GANY, GB, E, ANY, B],
acquire,
use,
release,
)
}

View File

@ -1,31 +0,0 @@
// Copyright (c) 2023 IBM Corp.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package generic
import (
"context"
ET "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/exec"
GE "github.com/IBM/fp-go/v2/internal/exec"
)
// Command executes a command
func Command[GA ~func() ET.Either[error, exec.CommandOutput]](name string, args []string, in []byte) GA {
return TryCatchError[GA](func() (exec.CommandOutput, error) {
return GE.Exec(context.Background(), name, args, in)
})
}

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@ package generic
import (
"time"
ET "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/either"
F "github.com/IBM/fp-go/v2/function"
C "github.com/IBM/fp-go/v2/internal/chain"
"github.com/IBM/fp-go/v2/internal/eithert"
@ -32,52 +32,52 @@ import (
// type IOEither[E, A any] = func() Either[E, A]
// Deprecated:
func MakeIO[GA ~func() ET.Either[E, A], E, A any](f GA) GA {
func MakeIO[GA ~func() either.Either[E, A], E, A any](f GA) GA {
return f
}
// Deprecated:
func Left[GA ~func() ET.Either[E, A], E, A any](l E) GA {
return MakeIO(eithert.Left(IO.MonadOf[GA, ET.Either[E, A]], l))
func Left[GA ~func() either.Either[E, A], E, A any](l E) GA {
return MakeIO(eithert.Left(IO.MonadOf[GA, either.Either[E, A]], l))
}
// Deprecated:
func Right[GA ~func() ET.Either[E, A], E, A any](r A) GA {
return MakeIO(eithert.Right(IO.MonadOf[GA, ET.Either[E, A]], r))
func Right[GA ~func() either.Either[E, A], E, A any](r A) GA {
return MakeIO(eithert.Right(IO.MonadOf[GA, either.Either[E, A]], r))
}
// Deprecated:
func Of[GA ~func() ET.Either[E, A], E, A any](r A) GA {
func Of[GA ~func() either.Either[E, A], E, A any](r A) GA {
return Right[GA](r)
}
// Deprecated:
func MonadOf[GA ~func() ET.Either[E, A], E, A any](r A) GA {
func MonadOf[GA ~func() either.Either[E, A], E, A any](r A) GA {
return Of[GA](r)
}
// Deprecated:
func LeftIO[GA ~func() ET.Either[E, A], GE ~func() E, E, A any](ml GE) GA {
return MakeIO(eithert.LeftF(IO.MonadMap[GE, GA, E, ET.Either[E, A]], ml))
func LeftIO[GA ~func() either.Either[E, A], GE ~func() E, E, A any](ml GE) GA {
return MakeIO(eithert.LeftF(IO.MonadMap[GE, GA, E, either.Either[E, A]], ml))
}
// Deprecated:
func RightIO[GA ~func() ET.Either[E, A], GR ~func() A, E, A any](mr GR) GA {
return MakeIO(eithert.RightF(IO.MonadMap[GR, GA, A, ET.Either[E, A]], mr))
func RightIO[GA ~func() either.Either[E, A], GR ~func() A, E, A any](mr GR) GA {
return MakeIO(eithert.RightF(IO.MonadMap[GR, GA, A, either.Either[E, A]], mr))
}
func FromEither[GA ~func() ET.Either[E, A], E, A any](e ET.Either[E, A]) GA {
func FromEither[GA ~func() either.Either[E, A], E, A any](e either.Either[E, A]) GA {
return IO.Of[GA](e)
}
func FromOption[GA ~func() ET.Either[E, A], E, A any](onNone func() E) func(o O.Option[A]) GA {
func FromOption[GA ~func() either.Either[E, A], E, A any](onNone func() E) func(o O.Option[A]) GA {
return FE.FromOption(
FromEither[GA, E, A],
onNone,
)
}
func ChainOptionK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](onNone func() E) func(func(A) O.Option[B]) func(GA) GB {
func ChainOptionK[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](onNone func() E) func(func(A) O.Option[B]) func(GA) GB {
return FE.ChainOptionK(
MonadChain[GA, GB, E, A, B],
FromEither[GB, E, B],
@ -86,50 +86,50 @@ func ChainOptionK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A,
}
// Deprecated:
func FromIO[GA ~func() ET.Either[E, A], GR ~func() A, E, A any](mr GR) GA {
func FromIO[GA ~func() either.Either[E, A], GR ~func() A, E, A any](mr GR) GA {
return RightIO[GA](mr)
}
// Deprecated:
func MonadMap[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](fa GA, f func(A) B) GB {
return eithert.MonadMap(IO.MonadMap[GA, GB, ET.Either[E, A], ET.Either[E, B]], fa, f)
func MonadMap[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](fa GA, f func(A) B) GB {
return eithert.MonadMap(IO.MonadMap[GA, GB, either.Either[E, A], either.Either[E, B]], fa, f)
}
// Deprecated:
func Map[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](f func(A) B) func(GA) GB {
return eithert.Map(IO.Map[GA, GB, ET.Either[E, A], ET.Either[E, B]], f)
func Map[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](f func(A) B) func(GA) GB {
return eithert.Map(IO.Map[GA, GB, either.Either[E, A], either.Either[E, B]], f)
}
// Deprecated:
func MonadMapTo[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](fa GA, b B) GB {
func MonadMapTo[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](fa GA, b B) GB {
return MonadMap[GA, GB](fa, F.Constant1[A](b))
}
// Deprecated:
func MapTo[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](b B) func(GA) GB {
func MapTo[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](b B) func(GA) GB {
return Map[GA, GB](F.Constant1[A](b))
}
// Deprecated:
func MonadChain[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](fa GA, f func(A) GB) GB {
return eithert.MonadChain(IO.MonadChain[GA, GB, ET.Either[E, A], ET.Either[E, B]], IO.MonadOf[GB, ET.Either[E, B]], fa, f)
func MonadChain[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](fa GA, f func(A) GB) GB {
return eithert.MonadChain(IO.MonadChain[GA, GB, either.Either[E, A], either.Either[E, B]], IO.MonadOf[GB, either.Either[E, B]], fa, f)
}
// Deprecated:
func Chain[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](f func(A) GB) func(GA) GB {
return eithert.Chain(IO.Chain[GA, GB, ET.Either[E, A], ET.Either[E, B]], IO.Of[GB, ET.Either[E, B]], f)
func Chain[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](f func(A) GB) func(GA) GB {
return eithert.Chain(IO.Chain[GA, GB, either.Either[E, A], either.Either[E, B]], IO.Of[GB, either.Either[E, B]], f)
}
func MonadChainTo[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](fa GA, fb GB) GB {
func MonadChainTo[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](fa GA, fb GB) GB {
return MonadChain(fa, F.Constant1[A](fb))
}
func ChainTo[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](fb GB) func(GA) GB {
func ChainTo[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](fb GB) func(GA) GB {
return Chain[GA, GB, E, A, B](F.Constant1[A](fb))
}
// Deprecated:
func MonadChainEitherK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](ma GA, f func(A) ET.Either[E, B]) GB {
func MonadChainEitherK[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](ma GA, f func(A) either.Either[E, B]) GB {
return FE.MonadChainEitherK(
MonadChain[GA, GB, E, A, B],
FromEither[GB, E, B],
@ -139,7 +139,7 @@ func MonadChainEitherK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E
}
// Deprecated:
func MonadChainIOK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GR ~func() B, E, A, B any](ma GA, f func(A) GR) GB {
func MonadChainIOK[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GR ~func() B, E, A, B any](ma GA, f func(A) GR) GB {
return FI.MonadChainIOK(
MonadChain[GA, GB, E, A, B],
FromIO[GB, GR, E, B],
@ -148,7 +148,7 @@ func MonadChainIOK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GR ~f
)
}
func ChainIOK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GR ~func() B, E, A, B any](f func(A) GR) func(GA) GB {
func ChainIOK[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GR ~func() B, E, A, B any](f func(A) GR) func(GA) GB {
return FI.ChainIOK(
Chain[GA, GB, E, A, B],
FromIO[GB, GR, E, B],
@ -157,7 +157,7 @@ func ChainIOK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], GR ~func()
}
// Deprecated:
func ChainEitherK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](f func(A) ET.Either[E, B]) func(GA) GB {
func ChainEitherK[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](f func(A) either.Either[E, B]) func(GA) GB {
return FE.ChainEitherK(
Chain[GA, GB, E, A, B],
FromEither[GB, E, B],
@ -166,93 +166,93 @@ func ChainEitherK[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A,
}
// Deprecated:
func MonadAp[GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B], GA ~func() ET.Either[E, A], E, A, B any](mab GAB, ma GA) GB {
func MonadAp[GB ~func() either.Either[E, B], GAB ~func() either.Either[E, func(A) B], GA ~func() either.Either[E, A], E, A, B any](mab GAB, ma GA) GB {
return eithert.MonadAp(
IO.MonadAp[GA, GB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, A], ET.Either[E, B]],
IO.MonadMap[GAB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
IO.MonadAp[GA, GB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, A], either.Either[E, B]],
IO.MonadMap[GAB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
mab, ma)
}
// Deprecated:
func Ap[GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B], GA ~func() ET.Either[E, A], E, A, B any](ma GA) func(GAB) GB {
func Ap[GB ~func() either.Either[E, B], GAB ~func() either.Either[E, func(A) B], GA ~func() either.Either[E, A], E, A, B any](ma GA) func(GAB) GB {
return eithert.Ap(
IO.Ap[GB, func() func(ET.Either[E, A]) ET.Either[E, B], GA, ET.Either[E, B], ET.Either[E, A]],
IO.Map[GAB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
IO.Ap[GB, func() func(either.Either[E, A]) either.Either[E, B], GA, either.Either[E, B], either.Either[E, A]],
IO.Map[GAB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
ma)
}
// Deprecated:
func MonadApSeq[GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B], GA ~func() ET.Either[E, A], E, A, B any](mab GAB, ma GA) GB {
func MonadApSeq[GB ~func() either.Either[E, B], GAB ~func() either.Either[E, func(A) B], GA ~func() either.Either[E, A], E, A, B any](mab GAB, ma GA) GB {
return eithert.MonadAp(
IO.MonadApSeq[GA, GB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, A], ET.Either[E, B]],
IO.MonadMap[GAB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
IO.MonadApSeq[GA, GB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, A], either.Either[E, B]],
IO.MonadMap[GAB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
mab, ma)
}
// Deprecated:
func ApSeq[GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B], GA ~func() ET.Either[E, A], E, A, B any](ma GA) func(GAB) GB {
func ApSeq[GB ~func() either.Either[E, B], GAB ~func() either.Either[E, func(A) B], GA ~func() either.Either[E, A], E, A, B any](ma GA) func(GAB) GB {
return eithert.Ap(
IO.ApSeq[GB, func() func(ET.Either[E, A]) ET.Either[E, B], GA, ET.Either[E, B], ET.Either[E, A]],
IO.Map[GAB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
IO.ApSeq[GB, func() func(either.Either[E, A]) either.Either[E, B], GA, either.Either[E, B], either.Either[E, A]],
IO.Map[GAB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
ma)
}
// Deprecated:
func MonadApPar[GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B], GA ~func() ET.Either[E, A], E, A, B any](mab GAB, ma GA) GB {
func MonadApPar[GB ~func() either.Either[E, B], GAB ~func() either.Either[E, func(A) B], GA ~func() either.Either[E, A], E, A, B any](mab GAB, ma GA) GB {
return eithert.MonadAp(
IO.MonadApPar[GA, GB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, A], ET.Either[E, B]],
IO.MonadMap[GAB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
IO.MonadApPar[GA, GB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, A], either.Either[E, B]],
IO.MonadMap[GAB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
mab, ma)
}
// Deprecated:
func ApPar[GB ~func() ET.Either[E, B], GAB ~func() ET.Either[E, func(A) B], GA ~func() ET.Either[E, A], E, A, B any](ma GA) func(GAB) GB {
func ApPar[GB ~func() either.Either[E, B], GAB ~func() either.Either[E, func(A) B], GA ~func() either.Either[E, A], E, A, B any](ma GA) func(GAB) GB {
return eithert.Ap(
IO.ApPar[GB, func() func(ET.Either[E, A]) ET.Either[E, B], GA, ET.Either[E, B], ET.Either[E, A]],
IO.Map[GAB, func() func(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
IO.ApPar[GB, func() func(either.Either[E, A]) either.Either[E, B], GA, either.Either[E, B], either.Either[E, A]],
IO.Map[GAB, func() func(either.Either[E, A]) either.Either[E, B], either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
ma)
}
// Deprecated:
func Flatten[GA ~func() ET.Either[E, A], GAA ~func() ET.Either[E, GA], E, A any](mma GAA) GA {
func Flatten[GA ~func() either.Either[E, A], GAA ~func() either.Either[E, GA], E, A any](mma GAA) GA {
return MonadChain(mma, F.Identity[GA])
}
// Deprecated:
func TryCatch[GA ~func() ET.Either[E, A], E, A any](f func() (A, error), onThrow func(error) E) GA {
return MakeIO(func() ET.Either[E, A] {
func TryCatch[GA ~func() either.Either[E, A], E, A any](f func() (A, error), onThrow func(error) E) GA {
return MakeIO(func() either.Either[E, A] {
a, err := f()
return ET.TryCatch(a, err, onThrow)
return either.TryCatch(a, err, onThrow)
})
}
// Deprecated:
func TryCatchError[GA ~func() ET.Either[error, A], A any](f func() (A, error)) GA {
return MakeIO(func() ET.Either[error, A] {
return ET.TryCatchError(f())
func TryCatchError[GA ~func() either.Either[error, A], A any](f func() (A, error)) GA {
return MakeIO(func() either.Either[error, A] {
return either.TryCatchError(f())
})
}
// Memoize computes the value of the provided IO monad lazily but exactly once
//
// Deprecated:
func Memoize[GA ~func() ET.Either[E, A], E, A any](ma GA) GA {
func Memoize[GA ~func() either.Either[E, A], E, A any](ma GA) GA {
return IO.Memoize(ma)
}
// Deprecated:
func MonadMapLeft[GA1 ~func() ET.Either[E1, A], GA2 ~func() ET.Either[E2, A], E1, E2, A any](fa GA1, f func(E1) E2) GA2 {
func MonadMapLeft[GA1 ~func() either.Either[E1, A], GA2 ~func() either.Either[E2, A], E1, E2, A any](fa GA1, f func(E1) E2) GA2 {
return eithert.MonadMapLeft(
IO.MonadMap[GA1, GA2, ET.Either[E1, A], ET.Either[E2, A]],
IO.MonadMap[GA1, GA2, either.Either[E1, A], either.Either[E2, A]],
fa,
f,
)
}
// Deprecated:
func MapLeft[GA1 ~func() ET.Either[E1, A], GA2 ~func() ET.Either[E2, A], E1, E2, A any](f func(E1) E2) func(GA1) GA2 {
func MapLeft[GA1 ~func() either.Either[E1, A], GA2 ~func() either.Either[E2, A], E1, E2, A any](f func(E1) E2) func(GA1) GA2 {
return eithert.MapLeft(
IO.Map[GA1, GA2, ET.Either[E1, A], ET.Either[E2, A]],
IO.Map[GA1, GA2, either.Either[E1, A], either.Either[E2, A]],
f,
)
}
@ -260,49 +260,49 @@ func MapLeft[GA1 ~func() ET.Either[E1, A], GA2 ~func() ET.Either[E2, A], E1, E2,
// Delay creates an operation that passes in the value after some [time.Duration]
//
// Deprecated:
func Delay[GA ~func() ET.Either[E, A], E, A any](delay time.Duration) func(GA) GA {
func Delay[GA ~func() either.Either[E, A], E, A any](delay time.Duration) func(GA) GA {
return IO.Delay[GA](delay)
}
// After creates an operation that passes after the given [time.Time]
//
// Deprecated:
func After[GA ~func() ET.Either[E, A], E, A any](timestamp time.Time) func(GA) GA {
func After[GA ~func() either.Either[E, A], E, A any](timestamp time.Time) func(GA) GA {
return IO.After[GA](timestamp)
}
// Deprecated:
func MonadBiMap[GA ~func() ET.Either[E1, A], GB ~func() ET.Either[E2, B], E1, E2, A, B any](fa GA, f func(E1) E2, g func(A) B) GB {
return eithert.MonadBiMap(IO.MonadMap[GA, GB, ET.Either[E1, A], ET.Either[E2, B]], fa, f, g)
func MonadBiMap[GA ~func() either.Either[E1, A], GB ~func() either.Either[E2, B], E1, E2, A, B any](fa GA, f func(E1) E2, g func(A) B) GB {
return eithert.MonadBiMap(IO.MonadMap[GA, GB, either.Either[E1, A], either.Either[E2, B]], fa, f, g)
}
// BiMap maps a pair of functions over the two type arguments of the bifunctor.
//
// Deprecated:
func BiMap[GA ~func() ET.Either[E1, A], GB ~func() ET.Either[E2, B], E1, E2, A, B any](f func(E1) E2, g func(A) B) func(GA) GB {
return eithert.BiMap(IO.Map[GA, GB, ET.Either[E1, A], ET.Either[E2, B]], f, g)
func BiMap[GA ~func() either.Either[E1, A], GB ~func() either.Either[E2, B], E1, E2, A, B any](f func(E1) E2, g func(A) B) func(GA) GB {
return eithert.BiMap(IO.Map[GA, GB, either.Either[E1, A], either.Either[E2, B]], f, g)
}
// Fold convers an IOEither into an IO
//
// Deprecated:
func Fold[GA ~func() ET.Either[E, A], GB ~func() B, E, A, B any](onLeft func(E) GB, onRight func(A) GB) func(GA) GB {
return eithert.MatchE(IO.MonadChain[GA, GB, ET.Either[E, A], B], onLeft, onRight)
func Fold[GA ~func() either.Either[E, A], GB ~func() B, E, A, B any](onLeft func(E) GB, onRight func(A) GB) func(GA) GB {
return eithert.MatchE(IO.MonadChain[GA, GB, either.Either[E, A], B], onLeft, onRight)
}
func MonadFold[GA ~func() ET.Either[E, A], GB ~func() B, E, A, B any](ma GA, onLeft func(E) GB, onRight func(A) GB) GB {
return eithert.FoldE(IO.MonadChain[GA, GB, ET.Either[E, A], B], ma, onLeft, onRight)
func MonadFold[GA ~func() either.Either[E, A], GB ~func() B, E, A, B any](ma GA, onLeft func(E) GB, onRight func(A) GB) GB {
return eithert.FoldE(IO.MonadChain[GA, GB, either.Either[E, A], B], ma, onLeft, onRight)
}
// GetOrElse extracts the value or maps the error
func GetOrElse[GA ~func() ET.Either[E, A], GB ~func() A, E, A any](onLeft func(E) GB) func(GA) GB {
return eithert.GetOrElse(IO.MonadChain[GA, GB, ET.Either[E, A], A], IO.MonadOf[GB, A], onLeft)
func GetOrElse[GA ~func() either.Either[E, A], GB ~func() A, E, A any](onLeft func(E) GB) func(GA) GB {
return eithert.GetOrElse(IO.MonadChain[GA, GB, either.Either[E, A], A], IO.MonadOf[GB, A], onLeft)
}
// MonadChainFirst runs the monad returned by the function but returns the result of the original monad
//
// Deprecated:
func MonadChainFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](ma GA, f func(A) GB) GA {
func MonadChainFirst[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](ma GA, f func(A) GB) GA {
return C.MonadChainFirst(
MonadChain[GA, GA, E, A, A],
MonadMap[GB, GA, E, B, A],
@ -314,7 +314,7 @@ func MonadChainFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E,
// ChainFirst runs the monad returned by the function but returns the result of the original monad
//
// Deprecated:
func ChainFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B any](f func(A) GB) func(GA) GA {
func ChainFirst[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], E, A, B any](f func(A) GB) func(GA) GA {
return C.ChainFirst(
Chain[GA, GA, E, A, A],
Map[GB, GA, E, B, A],
@ -325,11 +325,11 @@ func ChainFirst[GA ~func() ET.Either[E, A], GB ~func() ET.Either[E, B], E, A, B
// MonadChainFirstIOK runs the monad returned by the function but returns the result of the original monad
//
// Deprecated:
func MonadChainFirstIOK[GA ~func() ET.Either[E, A], GIOB ~func() B, E, A, B any](first GA, f func(A) GIOB) GA {
func MonadChainFirstIOK[GA ~func() either.Either[E, A], GIOB ~func() B, E, A, B any](first GA, f func(A) GIOB) GA {
return FI.MonadChainFirstIOK(
MonadChain[GA, GA, E, A, A],
MonadMap[func() ET.Either[E, B], GA, E, B, A],
FromIO[func() ET.Either[E, B], GIOB, E, B],
MonadMap[func() either.Either[E, B], GA, E, B, A],
FromIO[func() either.Either[E, B], GIOB, E, B],
first,
f,
)
@ -338,11 +338,11 @@ func MonadChainFirstIOK[GA ~func() ET.Either[E, A], GIOB ~func() B, E, A, B any]
// ChainFirstIOK runs the monad returned by the function but returns the result of the original monad
//
// Deprecated:
func ChainFirstIOK[GA ~func() ET.Either[E, A], GIOB ~func() B, E, A, B any](f func(A) GIOB) func(GA) GA {
func ChainFirstIOK[GA ~func() either.Either[E, A], GIOB ~func() B, E, A, B any](f func(A) GIOB) func(GA) GA {
return FI.ChainFirstIOK(
Chain[GA, GA, E, A, A],
Map[func() ET.Either[E, B], GA, E, B, A],
FromIO[func() ET.Either[E, B], GIOB, E, B],
Map[func() either.Either[E, B], GA, E, B, A],
FromIO[func() either.Either[E, B], GIOB, E, B],
f,
)
}
@ -350,11 +350,11 @@ func ChainFirstIOK[GA ~func() ET.Either[E, A], GIOB ~func() B, E, A, B any](f fu
// MonadChainFirstEitherK runs the monad returned by the function but returns the result of the original monad
//
// Deprecated:
func MonadChainFirstEitherK[GA ~func() ET.Either[E, A], E, A, B any](first GA, f func(A) ET.Either[E, B]) GA {
func MonadChainFirstEitherK[GA ~func() either.Either[E, A], E, A, B any](first GA, f func(A) either.Either[E, B]) GA {
return FE.MonadChainFirstEitherK(
MonadChain[GA, GA, E, A, A],
MonadMap[func() ET.Either[E, B], GA, E, B, A],
FromEither[func() ET.Either[E, B], E, B],
MonadMap[func() either.Either[E, B], GA, E, B, A],
FromEither[func() either.Either[E, B], E, B],
first,
f,
)
@ -363,11 +363,11 @@ func MonadChainFirstEitherK[GA ~func() ET.Either[E, A], E, A, B any](first GA, f
// ChainFirstEitherK runs the monad returned by the function but returns the result of the original monad
//
// Deprecated:
func ChainFirstEitherK[GA ~func() ET.Either[E, A], E, A, B any](f func(A) ET.Either[E, B]) func(GA) GA {
func ChainFirstEitherK[GA ~func() either.Either[E, A], E, A, B any](f func(A) either.Either[E, B]) func(GA) GA {
return FE.ChainFirstEitherK(
Chain[GA, GA, E, A, A],
Map[func() ET.Either[E, B], GA, E, B, A],
FromEither[func() ET.Either[E, B], E, B],
Map[func() either.Either[E, B], GA, E, B, A],
FromEither[func() either.Either[E, B], E, B],
f,
)
}
@ -375,14 +375,14 @@ func ChainFirstEitherK[GA ~func() ET.Either[E, A], E, A, B any](f func(A) ET.Eit
// Swap changes the order of type parameters
//
// Deprecated:
func Swap[GEA ~func() ET.Either[E, A], GAE ~func() ET.Either[A, E], E, A any](val GEA) GAE {
func Swap[GEA ~func() either.Either[E, A], GAE ~func() either.Either[A, E], E, A any](val GEA) GAE {
return MonadFold(val, Right[GAE], Left[GAE])
}
// FromImpure converts a side effect without a return value into a side effect that returns any
//
// Deprecated:
func FromImpure[GA ~func() ET.Either[E, any], IMP ~func(), E any](f IMP) GA {
func FromImpure[GA ~func() either.Either[E, any], IMP ~func(), E any](f IMP) GA {
return F.Pipe2(
f,
IO.FromImpure[func() any, IMP],
@ -393,12 +393,12 @@ func FromImpure[GA ~func() ET.Either[E, any], IMP ~func(), E any](f IMP) GA {
// Defer creates an IO by creating a brand new IO via a generator function, each time
//
// Deprecated:
func Defer[GEA ~func() ET.Either[E, A], E, A any](gen func() GEA) GEA {
func Defer[GEA ~func() either.Either[E, A], E, A any](gen func() GEA) GEA {
return IO.Defer[GEA](gen)
}
// Deprecated:
func MonadAlt[LAZY ~func() GIOA, GIOA ~func() ET.Either[E, A], E, A any](first GIOA, second LAZY) GIOA {
func MonadAlt[LAZY ~func() GIOA, GIOA ~func() either.Either[E, A], E, A any](first GIOA, second LAZY) GIOA {
return eithert.MonadAlt(
IO.Of[GIOA],
IO.MonadChain[GIOA, GIOA],
@ -409,29 +409,29 @@ func MonadAlt[LAZY ~func() GIOA, GIOA ~func() ET.Either[E, A], E, A any](first G
}
// Deprecated:
func Alt[LAZY ~func() GIOA, GIOA ~func() ET.Either[E, A], E, A any](second LAZY) func(GIOA) GIOA {
func Alt[LAZY ~func() GIOA, GIOA ~func() either.Either[E, A], E, A any](second LAZY) func(GIOA) GIOA {
return F.Bind2nd(MonadAlt[LAZY], second)
}
// Deprecated:
func MonadFlap[GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], E, B, A any](fab GEAB, a A) GEB {
func MonadFlap[GEAB ~func() either.Either[E, func(A) B], GEB ~func() either.Either[E, B], E, B, A any](fab GEAB, a A) GEB {
return FC.MonadFlap(MonadMap[GEAB, GEB], fab, a)
}
// Deprecated:
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() either.Either[E, func(A) B], GEB ~func() either.Either[E, B], E, B, A any](a A) func(GEAB) GEB {
return FC.Flap(Map[GEAB, GEB], a)
}
// Deprecated:
func ToIOOption[GA ~func() O.Option[A], GEA ~func() ET.Either[E, A], E, A any](ioe GEA) GA {
func ToIOOption[GA ~func() O.Option[A], GEA ~func() either.Either[E, A], E, A any](ioe GEA) GA {
return F.Pipe1(
ioe,
IO.Map[GEA, GA](ET.ToOption[E, A]),
IO.Map[GEA, GA](either.ToOption[E, A]),
)
}
// Deprecated:
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))
func FromIOOption[GEA ~func() either.Either[E, A], GA ~func() O.Option[A], E, A any](onNone func() E) func(ioo GA) GEA {
return IO.Map[GA, GEA](either.FromOption[A](onNone))
}

View File

@ -1,38 +0,0 @@
// Copyright (c) 2023 IBM Corp.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package generic
import (
ET "github.com/IBM/fp-go/v2/either"
GIO "github.com/IBM/fp-go/v2/io/generic"
R "github.com/IBM/fp-go/v2/retry"
)
// Retry combinator for actions that don't raise exceptions, but
// signal in their type the outcome has failed. Examples are the
// `Option`, `Either` and `EitherT` monads.
//
// policy - refers to the retry policy
// action - converts a status into an operation to be executed
// check - checks if the result of the action needs to be retried
func Retrying[GA ~func() ET.Either[E, A], E, A any](
policy R.RetryPolicy,
action func(R.RetryStatus) GA,
check func(ET.Either[E, A]) bool,
) GA {
// get an implementation for the types
return GIO.Retrying(policy, action, check)
}

View File

@ -16,18 +16,18 @@
package generic
import (
ET "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/either"
F "github.com/IBM/fp-go/v2/function"
RA "github.com/IBM/fp-go/v2/internal/array"
RR "github.com/IBM/fp-go/v2/internal/record"
)
// MonadTraverseArray transforms an array
func MonadTraverseArray[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
func MonadTraverseArray[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
return RA.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -35,22 +35,22 @@ func MonadTraverseArray[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS
}
// TraverseArray transforms an array
func TraverseArray[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
func TraverseArray[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
return RA.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// MonadTraverseArrayWithIndex transforms an array
func MonadTraverseArrayWithIndex[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
func MonadTraverseArrayWithIndex[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
return RA.MonadTraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -58,27 +58,27 @@ func MonadTraverseArrayWithIndex[GB ~func() ET.Either[E, B], GBS ~func() ET.Eith
}
// TraverseArrayWithIndex transforms an array
func TraverseArrayWithIndex[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
func TraverseArrayWithIndex[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
return RA.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceArray converts a homogeneous sequence of either into an either of sequence
func SequenceArray[GA ~func() ET.Either[E, A], GAS ~func() ET.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
func SequenceArray[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
return MonadTraverseArray[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseRecord transforms an array
func MonadTraverseRecord[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
func MonadTraverseRecord[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
return RR.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -86,38 +86,38 @@ func MonadTraverseRecord[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BB
}
// TraverseRecord transforms an array
func TraverseRecord[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
func TraverseRecord[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
return RR.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// TraverseRecordWithIndex transforms an array
func TraverseRecordWithIndex[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
func TraverseRecordWithIndex[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
return RR.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceRecord converts a homogeneous sequence of either into an either of sequence
func SequenceRecord[GA ~func() ET.Either[E, A], GAS ~func() ET.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
func SequenceRecord[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
return MonadTraverseRecord[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseArraySeq transforms an array
func MonadTraverseArraySeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
func MonadTraverseArraySeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
return RA.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -125,22 +125,22 @@ func MonadTraverseArraySeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
}
// TraverseArraySeq transforms an array
func TraverseArraySeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
func TraverseArraySeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
return RA.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// MonadTraverseArrayWithIndexSeq transforms an array
func MonadTraverseArrayWithIndexSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
func MonadTraverseArrayWithIndexSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
return RA.MonadTraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -148,27 +148,27 @@ func MonadTraverseArrayWithIndexSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.E
}
// TraverseArrayWithIndexSeq transforms an array
func TraverseArrayWithIndexSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
func TraverseArrayWithIndexSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
return RA.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceArraySeq converts a homogeneous sequence of either into an either of sequence
func SequenceArraySeq[GA ~func() ET.Either[E, A], GAS ~func() ET.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
func SequenceArraySeq[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
return MonadTraverseArraySeq[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseRecordSeq transforms an array
func MonadTraverseRecordSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
func MonadTraverseRecordSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
return RR.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -176,38 +176,38 @@ func MonadTraverseRecordSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
}
// TraverseRecordSeq transforms an array
func TraverseRecordSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
func TraverseRecordSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
return RR.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// TraverseRecordWithIndexSeq transforms an array
func TraverseRecordWithIndexSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
func TraverseRecordWithIndexSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
return RR.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceRecordSeq converts a homogeneous sequence of either into an either of sequence
func SequenceRecordSeq[GA ~func() ET.Either[E, A], GAS ~func() ET.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
func SequenceRecordSeq[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
return MonadTraverseRecordSeq[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseArrayPar transforms an array
func MonadTraverseArrayPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
func MonadTraverseArrayPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
return RA.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -215,22 +215,22 @@ func MonadTraverseArrayPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
}
// TraverseArrayPar transforms an array
func TraverseArrayPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
func TraverseArrayPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
return RA.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// MonadTraverseArrayWithIndexPar transforms an array
func MonadTraverseArrayWithIndexPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
func MonadTraverseArrayWithIndexPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
return RA.MonadTraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -238,27 +238,27 @@ func MonadTraverseArrayWithIndexPar[GB ~func() ET.Either[E, B], GBS ~func() ET.E
}
// TraverseArrayWithIndexPar transforms an array
func TraverseArrayWithIndexPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
func TraverseArrayWithIndexPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
return RA.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceArrayPar converts a homogeneous sequence of either into an either of sequence
func SequenceArrayPar[GA ~func() ET.Either[E, A], GAS ~func() ET.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
func SequenceArrayPar[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
return MonadTraverseArrayPar[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseRecordPar transforms an array
func MonadTraverseRecordPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
func MonadTraverseRecordPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
return RR.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
@ -266,28 +266,28 @@ func MonadTraverseRecordPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
}
// TraverseRecordPar transforms an array
func TraverseRecordPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
func TraverseRecordPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
return RR.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// TraverseRecordWithIndexPar transforms an array
func TraverseRecordWithIndexPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
func TraverseRecordWithIndexPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
return RR.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceRecordPar converts a homogeneous sequence of either into an either of sequence
func SequenceRecordPar[GA ~func() ET.Either[E, A], GAS ~func() ET.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
func SequenceRecordPar[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
return MonadTraverseRecordPar[GA, GAS](tas, F.Identity[GA])
}

View File

@ -24,7 +24,7 @@ import (
F "github.com/IBM/fp-go/v2/function"
R "github.com/IBM/fp-go/v2/http/builder"
H "github.com/IBM/fp-go/v2/http/headers"
IOE "github.com/IBM/fp-go/v2/ioeither"
"github.com/IBM/fp-go/v2/ioeither"
IOEH "github.com/IBM/fp-go/v2/ioeither/http"
LZ "github.com/IBM/fp-go/v2/lazy"
O "github.com/IBM/fp-go/v2/option"
@ -32,8 +32,8 @@ import (
func Requester(builder *R.Builder) IOEH.Requester {
withBody := F.Curry3(func(data []byte, url string, method string) IOE.IOEither[error, *http.Request] {
return IOE.TryCatchError(func() (*http.Request, error) {
withBody := F.Curry3(func(data []byte, url string, method string) ioeither.IOEither[error, *http.Request] {
return ioeither.TryCatchError(func() (*http.Request, error) {
req, err := http.NewRequest(method, url, bytes.NewReader(data))
if err == nil {
req.Header.Set(H.ContentLength, strconv.Itoa(len(data)))
@ -43,8 +43,8 @@ func Requester(builder *R.Builder) IOEH.Requester {
})
})
withoutBody := F.Curry2(func(url string, method string) IOE.IOEither[error, *http.Request] {
return IOE.TryCatchError(func() (*http.Request, error) {
withoutBody := F.Curry2(func(url string, method string) ioeither.IOEither[error, *http.Request] {
return ioeither.TryCatchError(func() (*http.Request, error) {
req, err := http.NewRequest(method, url, nil)
if err == nil {
H.Monoid.Concat(req.Header, builder.GetHeaders())
@ -56,10 +56,10 @@ func Requester(builder *R.Builder) IOEH.Requester {
return F.Pipe5(
builder.GetBody(),
O.Fold(LZ.Of(E.Of[error](withoutBody)), E.Map[error](withBody)),
E.Ap[func(string) IOE.IOEither[error, *http.Request]](builder.GetTargetURL()),
E.Flap[error, IOE.IOEither[error, *http.Request]](builder.GetMethod()),
E.GetOrElse(IOE.Left[*http.Request, error]),
IOE.Map[error](func(req *http.Request) *http.Request {
E.Ap[func(string) ioeither.IOEither[error, *http.Request]](builder.GetTargetURL()),
E.Flap[error, ioeither.IOEither[error, *http.Request]](builder.GetMethod()),
E.GetOrElse(ioeither.Left[*http.Request, error]),
ioeither.Map[error](func(req *http.Request) *http.Request {
req.Header = H.Monoid.Concat(req.Header, builder.GetHeaders())
return req
}),

View File

@ -24,7 +24,7 @@ import (
F "github.com/IBM/fp-go/v2/function"
R "github.com/IBM/fp-go/v2/http/builder"
IO "github.com/IBM/fp-go/v2/io"
IOE "github.com/IBM/fp-go/v2/ioeither"
"github.com/IBM/fp-go/v2/ioeither"
"github.com/stretchr/testify/assert"
)
@ -42,10 +42,10 @@ func TestBuilderWithQuery(t *testing.T) {
req := F.Pipe3(
b,
Requester,
IOE.Map[error](func(r *http.Request) *url.URL {
ioeither.Map[error](func(r *http.Request) *url.URL {
return r.URL
}),
IOE.ChainFirstIOK[error](func(u *url.URL) IO.IO[any] {
ioeither.ChainFirstIOK[error](func(u *url.URL) IO.IO[any] {
return IO.FromImpure(func() {
q := u.Query()
assert.Equal(t, "10", q.Get("limit"))

View File

@ -19,14 +19,14 @@ import (
"net/http"
DI "github.com/IBM/fp-go/v2/di"
IOE "github.com/IBM/fp-go/v2/ioeither"
"github.com/IBM/fp-go/v2/ioeither"
IOEH "github.com/IBM/fp-go/v2/ioeither/http"
)
var (
// InjHttpClient is the [DI.InjectionToken] for the [http.DefaultClient]
InjHttpClient = DI.MakeTokenWithDefault0("HTTP_CLIENT", IOE.Of[error](http.DefaultClient))
InjHttpClient = DI.MakeTokenWithDefault0("HTTP_CLIENT", ioeither.Of[error](http.DefaultClient))
// InjClient is the [DI.InjectionToken] for the default [IOEH.Client]
InjClient = DI.MakeTokenWithDefault1("CLIENT", InjHttpClient.IOEither(), IOE.Map[error](IOEH.MakeClient))
InjClient = DI.MakeTokenWithDefault1("CLIENT", InjHttpClient.IOEither(), ioeither.Map[error](IOEH.MakeClient))
)

View File

@ -24,7 +24,7 @@ import (
FL "github.com/IBM/fp-go/v2/file"
F "github.com/IBM/fp-go/v2/function"
H "github.com/IBM/fp-go/v2/http"
IOE "github.com/IBM/fp-go/v2/ioeither"
"github.com/IBM/fp-go/v2/ioeither"
IOEF "github.com/IBM/fp-go/v2/ioeither/file"
J "github.com/IBM/fp-go/v2/json"
P "github.com/IBM/fp-go/v2/pair"
@ -32,21 +32,21 @@ import (
type (
// Requester is a reader that constructs a request
Requester = IOE.IOEither[error, *http.Request]
Requester = ioeither.IOEither[error, *http.Request]
Client interface {
Do(Requester) IOE.IOEither[error, *http.Response]
Do(Requester) ioeither.IOEither[error, *http.Response]
}
client struct {
delegate *http.Client
doIOE func(*http.Request) IOE.IOEither[error, *http.Response]
doIOE func(*http.Request) ioeither.IOEither[error, *http.Response]
}
)
var (
// MakeRequest is an eitherized version of [http.NewRequest]
MakeRequest = IOE.Eitherize3(http.NewRequest)
MakeRequest = ioeither.Eitherize3(http.NewRequest)
makeRequest = F.Bind13of3(MakeRequest)
// specialize
@ -54,92 +54,92 @@ var (
)
// MakeBodyRequest creates a request that carries a body
func MakeBodyRequest(method string, body IOE.IOEither[error, []byte]) func(url string) IOE.IOEither[error, *http.Request] {
func MakeBodyRequest(method string, body ioeither.IOEither[error, []byte]) func(url string) ioeither.IOEither[error, *http.Request] {
onBody := F.Pipe1(
body,
IOE.Map[error](F.Flow2(
ioeither.Map[error](F.Flow2(
bytes.NewReader,
FL.ToReader[*bytes.Reader],
)),
)
onRelease := IOE.Of[error, io.Reader]
onRelease := ioeither.Of[error, io.Reader]
withMethod := F.Bind1of3(MakeRequest)(method)
return F.Flow2(
F.Bind1of2(withMethod),
IOE.WithResource[*http.Request](onBody, onRelease),
ioeither.WithResource[*http.Request](onBody, onRelease),
)
}
func (client client) Do(req Requester) IOE.IOEither[error, *http.Response] {
func (client client) Do(req Requester) ioeither.IOEither[error, *http.Response] {
return F.Pipe1(
req,
IOE.Chain(client.doIOE),
ioeither.Chain(client.doIOE),
)
}
func MakeClient(httpClient *http.Client) Client {
return client{delegate: httpClient, doIOE: IOE.Eitherize1(httpClient.Do)}
return client{delegate: httpClient, doIOE: ioeither.Eitherize1(httpClient.Do)}
}
// ReadFullResponse sends a request, reads the response as a byte array and represents the result as a tuple
func ReadFullResponse(client Client) func(Requester) IOE.IOEither[error, H.FullResponse] {
func ReadFullResponse(client Client) func(Requester) ioeither.IOEither[error, H.FullResponse] {
return F.Flow3(
client.Do,
IOE.ChainEitherK(H.ValidateResponse),
IOE.Chain(func(resp *http.Response) IOE.IOEither[error, H.FullResponse] {
ioeither.ChainEitherK(H.ValidateResponse),
ioeither.Chain(func(resp *http.Response) ioeither.IOEither[error, H.FullResponse] {
return F.Pipe1(
F.Pipe3(
resp,
H.GetBody,
IOE.Of[error, io.ReadCloser],
ioeither.Of[error, io.ReadCloser],
IOEF.ReadAll[io.ReadCloser],
),
IOE.Map[error](F.Bind1st(P.MakePair[*http.Response, []byte], resp)),
ioeither.Map[error](F.Bind1st(P.MakePair[*http.Response, []byte], resp)),
)
}),
)
}
// ReadAll sends a request and reads the response as bytes
func ReadAll(client Client) func(Requester) IOE.IOEither[error, []byte] {
func ReadAll(client Client) func(Requester) ioeither.IOEither[error, []byte] {
return F.Flow2(
ReadFullResponse(client),
IOE.Map[error](H.Body),
ioeither.Map[error](H.Body),
)
}
// ReadText sends a request, reads the response and represents the response as a text string
func ReadText(client Client) func(Requester) IOE.IOEither[error, string] {
func ReadText(client Client) func(Requester) ioeither.IOEither[error, string] {
return F.Flow2(
ReadAll(client),
IOE.Map[error](B.ToString),
ioeither.Map[error](B.ToString),
)
}
// ReadJson sends a request, reads the response and parses the response as JSON
//
// Deprecated: use [ReadJSON] instead
func ReadJson[A any](client Client) func(Requester) IOE.IOEither[error, A] {
func ReadJson[A any](client Client) func(Requester) ioeither.IOEither[error, A] {
return ReadJSON[A](client)
}
// readJSON sends a request, reads the response and parses the response as a []byte
func readJSON(client Client) func(Requester) IOE.IOEither[error, []byte] {
func readJSON(client Client) func(Requester) ioeither.IOEither[error, []byte] {
return F.Flow3(
ReadFullResponse(client),
IOE.ChainFirstEitherK(F.Flow2(
ioeither.ChainFirstEitherK(F.Flow2(
H.Response,
H.ValidateJSONResponse,
)),
IOE.Map[error](H.Body),
ioeither.Map[error](H.Body),
)
}
// ReadJSON sends a request, reads the response and parses the response as JSON
func ReadJSON[A any](client Client) func(Requester) IOE.IOEither[error, A] {
func ReadJSON[A any](client Client) func(Requester) ioeither.IOEither[error, A] {
return F.Flow2(
readJSON(client),
IOE.ChainEitherK[error](J.Unmarshal[A]),
ioeither.ChainEitherK[error](J.Unmarshal[A]),
)
}

View File

@ -25,7 +25,7 @@ import (
E "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/errors"
F "github.com/IBM/fp-go/v2/function"
IOE "github.com/IBM/fp-go/v2/ioeither"
"github.com/IBM/fp-go/v2/ioeither"
O "github.com/IBM/fp-go/v2/option"
R "github.com/IBM/fp-go/v2/retry"
"github.com/stretchr/testify/assert"
@ -51,7 +51,7 @@ func TestRetryHttp(t *testing.T) {
urls := AR.From("https://jsonplaceholder1.typicode.com/posts/1", "https://jsonplaceholder2.typicode.com/posts/1", "https://jsonplaceholder3.typicode.com/posts/1", "https://jsonplaceholder4.typicode.com/posts/1", "https://jsonplaceholder.typicode.com/posts/1")
client := MakeClient(&http.Client{})
action := func(status R.RetryStatus) IOE.IOEither[error, *PostItem] {
action := func(status R.RetryStatus) ioeither.IOEither[error, *PostItem] {
return F.Pipe1(
MakeGetRequest(urls[status.IterNumber]),
ReadJSON[*PostItem](client),
@ -66,6 +66,6 @@ func TestRetryHttp(t *testing.T) {
F.Constant1[*PostItem](false),
)
item := IOE.Retrying(testLogPolicy, action, check)()
item := ioeither.Retrying(testLogPolicy, action, check)()
assert.True(t, E.IsRight(item))
}

View File

@ -16,8 +16,8 @@
package ioeither
import (
ET "github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/ioeither/generic"
"github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/io"
R "github.com/IBM/fp-go/v2/retry"
)
@ -29,7 +29,7 @@ import (
func Retrying[E, A any](
policy R.RetryPolicy,
action func(R.RetryStatus) IOEither[E, A],
check func(ET.Either[E, A]) bool,
check func(either.Either[E, A]) bool,
) IOEither[E, A] {
return G.Retrying(policy, action, check)
return io.Retrying(policy, action, check)
}

View File

@ -18,10 +18,10 @@ package testing
import (
"testing"
ET "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/either"
EQ "github.com/IBM/fp-go/v2/eq"
L "github.com/IBM/fp-go/v2/internal/monad/testing"
IOE "github.com/IBM/fp-go/v2/ioeither"
"github.com/IBM/fp-go/v2/ioeither"
)
// AssertLaws asserts the apply monad laws for the `IOEither` monad
@ -36,38 +36,38 @@ func AssertLaws[E, A, B, C any](t *testing.T,
) func(a A) bool {
return L.AssertLaws(t,
IOE.Eq(ET.Eq(eqe, eqa)),
IOE.Eq(ET.Eq(eqe, eqb)),
IOE.Eq(ET.Eq(eqe, eqc)),
ioeither.Eq(either.Eq(eqe, eqa)),
ioeither.Eq(either.Eq(eqe, eqb)),
ioeither.Eq(either.Eq(eqe, eqc)),
IOE.Of[E, A],
IOE.Of[E, B],
IOE.Of[E, C],
ioeither.Of[E, A],
ioeither.Of[E, B],
ioeither.Of[E, C],
IOE.Of[E, func(A) A],
IOE.Of[E, func(A) B],
IOE.Of[E, func(B) C],
IOE.Of[E, func(func(A) B) B],
ioeither.Of[E, func(A) A],
ioeither.Of[E, func(A) B],
ioeither.Of[E, func(B) C],
ioeither.Of[E, func(func(A) B) B],
IOE.MonadMap[E, A, A],
IOE.MonadMap[E, A, B],
IOE.MonadMap[E, A, C],
IOE.MonadMap[E, B, C],
ioeither.MonadMap[E, A, A],
ioeither.MonadMap[E, A, B],
ioeither.MonadMap[E, A, C],
ioeither.MonadMap[E, B, C],
IOE.MonadMap[E, func(B) C, func(func(A) B) func(A) C],
ioeither.MonadMap[E, func(B) C, func(func(A) B) func(A) C],
IOE.MonadChain[E, A, A],
IOE.MonadChain[E, A, B],
IOE.MonadChain[E, A, C],
IOE.MonadChain[E, B, C],
ioeither.MonadChain[E, A, A],
ioeither.MonadChain[E, A, B],
ioeither.MonadChain[E, A, C],
ioeither.MonadChain[E, B, C],
IOE.MonadAp[A, E, A],
IOE.MonadAp[B, E, A],
IOE.MonadAp[C, E, B],
IOE.MonadAp[C, E, A],
ioeither.MonadAp[A, E, A],
ioeither.MonadAp[B, E, A],
ioeither.MonadAp[C, E, B],
ioeither.MonadAp[C, E, A],
IOE.MonadAp[B, E, func(A) B],
IOE.MonadAp[func(A) C, E, func(A) B],
ioeither.MonadAp[B, E, func(A) B],
ioeither.MonadAp[func(A) C, E, func(A) B],
ab,
bc,