mirror of
https://github.com/IBM/fp-go.git
synced 2025-07-17 01:32:23 +02:00
fix: refactorY
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@ -16,8 +16,9 @@
|
|||||||
package ioeither
|
package ioeither
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ET "github.com/IBM/fp-go/v2/either"
|
"github.com/IBM/fp-go/v2/either"
|
||||||
G "github.com/IBM/fp-go/v2/ioeither/generic"
|
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
|
// 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](
|
func Bracket[E, A, B, ANY any](
|
||||||
acquire IOEither[E, A],
|
acquire IOEither[E, A],
|
||||||
use func(A) IOEither[E, B],
|
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] {
|
) 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,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -16,17 +16,17 @@
|
|||||||
package ioeither
|
package ioeither
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ET "github.com/IBM/fp-go/v2/either"
|
"github.com/IBM/fp-go/v2/either"
|
||||||
EQ "github.com/IBM/fp-go/v2/eq"
|
EQ "github.com/IBM/fp-go/v2/eq"
|
||||||
IO "github.com/IBM/fp-go/v2/io"
|
IO "github.com/IBM/fp-go/v2/io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Eq implements the equals predicate for values contained in the IOEither monad
|
// 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)
|
return IO.Eq(eq)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function
|
// FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function
|
||||||
func FromStrictEquals[E, A comparable]() EQ.Eq[IOEither[E, A]] {
|
func FromStrictEquals[E, A comparable]() EQ.Eq[IOEither[E, A]] {
|
||||||
return Eq(ET.FromStrictEquals[E, A]())
|
return Eq(either.FromStrictEquals[E, A]())
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,21 @@
|
|||||||
package exec
|
package exec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/IBM/fp-go/v2/exec"
|
"github.com/IBM/fp-go/v2/exec"
|
||||||
F "github.com/IBM/fp-go/v2/function"
|
F "github.com/IBM/fp-go/v2/function"
|
||||||
IOE "github.com/IBM/fp-go/v2/ioeither"
|
INTE "github.com/IBM/fp-go/v2/internal/exec"
|
||||||
G "github.com/IBM/fp-go/v2/ioeither/generic"
|
"github.com/IBM/fp-go/v2/ioeither"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Command executes a command
|
// 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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
E "github.com/IBM/fp-go/v2/either"
|
E "github.com/IBM/fp-go/v2/either"
|
||||||
"github.com/IBM/fp-go/v2/exec"
|
"github.com/IBM/fp-go/v2/exec"
|
||||||
F "github.com/IBM/fp-go/v2/function"
|
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"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func TestOpenSSL(t *testing.T) {
|
|||||||
// execute the openSSL binary
|
// execute the openSSL binary
|
||||||
version := F.Pipe1(
|
version := F.Pipe1(
|
||||||
Command("openssl")(RA.From("version"))(B.Monoid.Empty()),
|
Command("openssl")(RA.From("version"))(B.Monoid.Empty()),
|
||||||
IOE.Map[error](F.Flow3(
|
ioeither.Map[error](F.Flow3(
|
||||||
exec.StdOut,
|
exec.StdOut,
|
||||||
B.ToString,
|
B.ToString,
|
||||||
strings.TrimSpace,
|
strings.TrimSpace,
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
package generic
|
package generic
|
||||||
|
|
||||||
import (
|
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"
|
G "github.com/IBM/fp-go/v2/internal/apply"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MonadApFirst combines two effectful actions, keeping only the result of the first.
|
// 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(
|
return G.MonadApFirst(
|
||||||
MonadAp[GA, GBA, GB],
|
MonadAp[GA, GBA, GB],
|
||||||
MonadMap[GA, GBA, E, A, func(B) A],
|
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.
|
// 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(
|
return G.ApFirst(
|
||||||
MonadAp[GA, GBA, GB],
|
MonadAp[GA, GBA, GB],
|
||||||
MonadMap[GA, GBA, E, A, func(B) A],
|
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.
|
// 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(
|
return G.MonadApSecond(
|
||||||
MonadAp[GB, GBB, GB],
|
MonadAp[GB, GBB, GB],
|
||||||
MonadMap[GA, GBB, E, A, func(B) B],
|
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.
|
// 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(
|
return G.ApSecond(
|
||||||
MonadAp[GB, GBB, GB],
|
MonadAp[GB, GBB, GB],
|
||||||
MonadMap[GA, GBB, E, A, func(B) B],
|
MonadMap[GA, GBB, E, A, func(B) B],
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
package generic
|
package generic
|
||||||
|
|
||||||
import (
|
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"
|
A "github.com/IBM/fp-go/v2/internal/apply"
|
||||||
C "github.com/IBM/fp-go/v2/internal/chain"
|
C "github.com/IBM/fp-go/v2/internal/chain"
|
||||||
F "github.com/IBM/fp-go/v2/internal/functor"
|
F "github.com/IBM/fp-go/v2/internal/functor"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bind creates an empty context of type [S] to be used with the [Bind] operation
|
// 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,
|
empty S,
|
||||||
) GS {
|
) GS {
|
||||||
return Of[GS, E, S](empty)
|
return Of[GS, E, S](empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind attaches the result of a computation to a context [S1] to produce a context [S2]
|
// 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,
|
setter func(T) func(S1) S2,
|
||||||
f func(S1) GT,
|
f func(S1) GT,
|
||||||
) func(GS1) GS2 {
|
) 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]
|
// 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,
|
key func(T) func(S1) S2,
|
||||||
f func(S1) T,
|
f func(S1) T,
|
||||||
) func(GS1) GS2 {
|
) 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]
|
// 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,
|
key func(B) func(S1) S2,
|
||||||
b B,
|
b B,
|
||||||
) func(GS1) GS2 {
|
) 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]
|
// 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,
|
setter func(T) S1,
|
||||||
) func(GT) GS1 {
|
) func(GT) GS1 {
|
||||||
return C.BindTo(
|
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
|
// 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,
|
setter func(T) func(S1) S2,
|
||||||
fa GT,
|
fa GT,
|
||||||
) func(GS1) GS2 {
|
) func(GS1) GS2 {
|
||||||
return A.ApS(
|
return A.ApS(
|
||||||
Ap[GS2, func() ET.Either[E, func(T) S2], GT, E, T, S2],
|
Ap[GS2, func() either.Either[E, func(T) S2], GT, E, T, S2],
|
||||||
Map[GS1, func() ET.Either[E, func(T) S2], E, S1, func(T) S2],
|
Map[GS1, func() either.Either[E, func(T) S2], E, S1, func(T) S2],
|
||||||
setter,
|
setter,
|
||||||
fa,
|
fa,
|
||||||
)
|
)
|
||||||
|
@ -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,
|
|
||||||
)
|
|
||||||
}
|
|
@ -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
@ -18,7 +18,7 @@ package generic
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ET "github.com/IBM/fp-go/v2/either"
|
"github.com/IBM/fp-go/v2/either"
|
||||||
F "github.com/IBM/fp-go/v2/function"
|
F "github.com/IBM/fp-go/v2/function"
|
||||||
C "github.com/IBM/fp-go/v2/internal/chain"
|
C "github.com/IBM/fp-go/v2/internal/chain"
|
||||||
"github.com/IBM/fp-go/v2/internal/eithert"
|
"github.com/IBM/fp-go/v2/internal/eithert"
|
||||||
@ -32,52 +32,52 @@ import (
|
|||||||
// type IOEither[E, A any] = func() Either[E, A]
|
// type IOEither[E, A any] = func() Either[E, A]
|
||||||
|
|
||||||
// Deprecated:
|
// 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
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// Deprecated:
|
||||||
func Left[GA ~func() ET.Either[E, A], E, A any](l E) GA {
|
func Left[GA ~func() either.Either[E, A], E, A any](l E) GA {
|
||||||
return MakeIO(eithert.Left(IO.MonadOf[GA, ET.Either[E, A]], l))
|
return MakeIO(eithert.Left(IO.MonadOf[GA, either.Either[E, A]], l))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// Deprecated:
|
||||||
func Right[GA ~func() ET.Either[E, A], E, A any](r A) GA {
|
func Right[GA ~func() either.Either[E, A], E, A any](r A) GA {
|
||||||
return MakeIO(eithert.Right(IO.MonadOf[GA, ET.Either[E, A]], r))
|
return MakeIO(eithert.Right(IO.MonadOf[GA, either.Either[E, A]], r))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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)
|
return Right[GA](r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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)
|
return Of[GA](r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// Deprecated:
|
||||||
func LeftIO[GA ~func() ET.Either[E, A], GE ~func() E, E, A any](ml GE) GA {
|
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, ET.Either[E, A]], ml))
|
return MakeIO(eithert.LeftF(IO.MonadMap[GE, GA, E, either.Either[E, A]], ml))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// Deprecated:
|
||||||
func RightIO[GA ~func() ET.Either[E, A], GR ~func() A, E, A any](mr GR) GA {
|
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, ET.Either[E, A]], mr))
|
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)
|
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(
|
return FE.FromOption(
|
||||||
FromEither[GA, E, A],
|
FromEither[GA, E, A],
|
||||||
onNone,
|
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(
|
return FE.ChainOptionK(
|
||||||
MonadChain[GA, GB, E, A, B],
|
MonadChain[GA, GB, E, A, B],
|
||||||
FromEither[GB, E, 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:
|
// 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)
|
return RightIO[GA](mr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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 {
|
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, ET.Either[E, A], ET.Either[E, B]], fa, f)
|
return eithert.MonadMap(IO.MonadMap[GA, GB, either.Either[E, A], either.Either[E, B]], fa, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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 {
|
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, ET.Either[E, A], ET.Either[E, B]], f)
|
return eithert.Map(IO.Map[GA, GB, either.Either[E, A], either.Either[E, B]], f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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))
|
return MonadMap[GA, GB](fa, F.Constant1[A](b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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))
|
return Map[GA, GB](F.Constant1[A](b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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 {
|
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, ET.Either[E, A], ET.Either[E, B]], IO.MonadOf[GB, ET.Either[E, B]], fa, f)
|
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:
|
// 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 {
|
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, ET.Either[E, A], ET.Either[E, B]], IO.Of[GB, ET.Either[E, B]], f)
|
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))
|
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))
|
return Chain[GA, GB, E, A, B](F.Constant1[A](fb))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
return FE.MonadChainEitherK(
|
||||||
MonadChain[GA, GB, E, A, B],
|
MonadChain[GA, GB, E, A, B],
|
||||||
FromEither[GB, E, 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:
|
// 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(
|
return FI.MonadChainIOK(
|
||||||
MonadChain[GA, GB, E, A, B],
|
MonadChain[GA, GB, E, A, B],
|
||||||
FromIO[GB, GR, E, 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(
|
return FI.ChainIOK(
|
||||||
Chain[GA, GB, E, A, B],
|
Chain[GA, GB, E, A, B],
|
||||||
FromIO[GB, GR, E, 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:
|
// 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(
|
return FE.ChainEitherK(
|
||||||
Chain[GA, GB, E, A, B],
|
Chain[GA, GB, E, A, B],
|
||||||
FromEither[GB, E, 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:
|
// 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(
|
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.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(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.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)
|
mab, ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
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.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(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
|
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)
|
ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
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.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(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.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)
|
mab, ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
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.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(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
|
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)
|
ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
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.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(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.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)
|
mab, ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
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.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(ET.Either[E, A]) ET.Either[E, B], ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]],
|
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)
|
ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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])
|
return MonadChain(mma, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// Deprecated:
|
||||||
func TryCatch[GA ~func() ET.Either[E, A], E, A any](f func() (A, error), onThrow func(error) E) GA {
|
func TryCatch[GA ~func() either.Either[E, A], E, A any](f func() (A, error), onThrow func(error) E) GA {
|
||||||
return MakeIO(func() ET.Either[E, A] {
|
return MakeIO(func() either.Either[E, A] {
|
||||||
a, err := f()
|
a, err := f()
|
||||||
return ET.TryCatch(a, err, onThrow)
|
return either.TryCatch(a, err, onThrow)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// Deprecated:
|
||||||
func TryCatchError[GA ~func() ET.Either[error, A], A any](f func() (A, error)) GA {
|
func TryCatchError[GA ~func() either.Either[error, A], A any](f func() (A, error)) GA {
|
||||||
return MakeIO(func() ET.Either[error, A] {
|
return MakeIO(func() either.Either[error, A] {
|
||||||
return ET.TryCatchError(f())
|
return either.TryCatchError(f())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memoize computes the value of the provided IO monad lazily but exactly once
|
// Memoize computes the value of the provided IO monad lazily but exactly once
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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)
|
return IO.Memoize(ma)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
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,
|
fa,
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
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,
|
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]
|
// Delay creates an operation that passes in the value after some [time.Duration]
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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)
|
return IO.Delay[GA](delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
// After creates an operation that passes after the given [time.Time]
|
// After creates an operation that passes after the given [time.Time]
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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)
|
return IO.After[GA](timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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 {
|
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, ET.Either[E1, A], ET.Either[E2, B]], fa, f, g)
|
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.
|
// BiMap maps a pair of functions over the two type arguments of the bifunctor.
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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 {
|
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, ET.Either[E1, A], ET.Either[E2, B]], f, g)
|
return eithert.BiMap(IO.Map[GA, GB, either.Either[E1, A], either.Either[E2, B]], f, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fold convers an IOEither into an IO
|
// Fold convers an IOEither into an IO
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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 {
|
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, ET.Either[E, A], B], onLeft, onRight)
|
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 {
|
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, ET.Either[E, A], B], ma, onLeft, onRight)
|
return eithert.FoldE(IO.MonadChain[GA, GB, either.Either[E, A], B], ma, onLeft, onRight)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrElse extracts the value or maps the error
|
// 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 {
|
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, ET.Either[E, A], A], IO.MonadOf[GB, A], onLeft)
|
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
|
// MonadChainFirst runs the monad returned by the function but returns the result of the original monad
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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(
|
return C.MonadChainFirst(
|
||||||
MonadChain[GA, GA, E, A, A],
|
MonadChain[GA, GA, E, A, A],
|
||||||
MonadMap[GB, GA, E, B, 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
|
// ChainFirst runs the monad returned by the function but returns the result of the original monad
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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(
|
return C.ChainFirst(
|
||||||
Chain[GA, GA, E, A, A],
|
Chain[GA, GA, E, A, A],
|
||||||
Map[GB, GA, E, B, 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
|
// MonadChainFirstIOK runs the monad returned by the function but returns the result of the original monad
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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(
|
return FI.MonadChainFirstIOK(
|
||||||
MonadChain[GA, GA, E, A, A],
|
MonadChain[GA, GA, E, A, A],
|
||||||
MonadMap[func() ET.Either[E, B], GA, E, B, A],
|
MonadMap[func() either.Either[E, B], GA, E, B, A],
|
||||||
FromIO[func() ET.Either[E, B], GIOB, E, B],
|
FromIO[func() either.Either[E, B], GIOB, E, B],
|
||||||
first,
|
first,
|
||||||
f,
|
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
|
// ChainFirstIOK runs the monad returned by the function but returns the result of the original monad
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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(
|
return FI.ChainFirstIOK(
|
||||||
Chain[GA, GA, E, A, A],
|
Chain[GA, GA, E, A, A],
|
||||||
Map[func() ET.Either[E, B], GA, E, B, A],
|
Map[func() either.Either[E, B], GA, E, B, A],
|
||||||
FromIO[func() ET.Either[E, B], GIOB, E, B],
|
FromIO[func() either.Either[E, B], GIOB, E, B],
|
||||||
f,
|
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
|
// MonadChainFirstEitherK runs the monad returned by the function but returns the result of the original monad
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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(
|
return FE.MonadChainFirstEitherK(
|
||||||
MonadChain[GA, GA, E, A, A],
|
MonadChain[GA, GA, E, A, A],
|
||||||
MonadMap[func() ET.Either[E, B], GA, E, B, A],
|
MonadMap[func() either.Either[E, B], GA, E, B, A],
|
||||||
FromEither[func() ET.Either[E, B], E, B],
|
FromEither[func() either.Either[E, B], E, B],
|
||||||
first,
|
first,
|
||||||
f,
|
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
|
// ChainFirstEitherK runs the monad returned by the function but returns the result of the original monad
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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(
|
return FE.ChainFirstEitherK(
|
||||||
Chain[GA, GA, E, A, A],
|
Chain[GA, GA, E, A, A],
|
||||||
Map[func() ET.Either[E, B], GA, E, B, A],
|
Map[func() either.Either[E, B], GA, E, B, A],
|
||||||
FromEither[func() ET.Either[E, B], E, B],
|
FromEither[func() either.Either[E, B], E, B],
|
||||||
f,
|
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
|
// Swap changes the order of type parameters
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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])
|
return MonadFold(val, Right[GAE], Left[GAE])
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromImpure converts a side effect without a return value into a side effect that returns any
|
// FromImpure converts a side effect without a return value into a side effect that returns any
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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(
|
return F.Pipe2(
|
||||||
f,
|
f,
|
||||||
IO.FromImpure[func() any, IMP],
|
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
|
// Defer creates an IO by creating a brand new IO via a generator function, each time
|
||||||
//
|
//
|
||||||
// Deprecated:
|
// 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)
|
return IO.Defer[GEA](gen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
return eithert.MonadAlt(
|
||||||
IO.Of[GIOA],
|
IO.Of[GIOA],
|
||||||
IO.MonadChain[GIOA, 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:
|
// 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)
|
return F.Bind2nd(MonadAlt[LAZY], second)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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)
|
return FC.MonadFlap(MonadMap[GEAB, GEB], fab, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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)
|
return FC.Flap(Map[GEAB, GEB], a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// 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(
|
return F.Pipe1(
|
||||||
ioe,
|
ioe,
|
||||||
IO.Map[GEA, GA](ET.ToOption[E, A]),
|
IO.Map[GEA, GA](either.ToOption[E, A]),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated:
|
// Deprecated:
|
||||||
func FromIOOption[GEA ~func() ET.Either[E, A], GA ~func() O.Option[A], E, A any](onNone func() E) func(ioo GA) GEA {
|
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](ET.FromOption[A](onNone))
|
return IO.Map[GA, GEA](either.FromOption[A](onNone))
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
|
@ -16,18 +16,18 @@
|
|||||||
package generic
|
package generic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ET "github.com/IBM/fp-go/v2/either"
|
"github.com/IBM/fp-go/v2/either"
|
||||||
F "github.com/IBM/fp-go/v2/function"
|
F "github.com/IBM/fp-go/v2/function"
|
||||||
RA "github.com/IBM/fp-go/v2/internal/array"
|
RA "github.com/IBM/fp-go/v2/internal/array"
|
||||||
RR "github.com/IBM/fp-go/v2/internal/record"
|
RR "github.com/IBM/fp-go/v2/internal/record"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MonadTraverseArray transforms an array
|
// 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](
|
return RA.MonadTraverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
|
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -35,22 +35,22 @@ func MonadTraverseArray[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BBS
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArray transforms an array
|
// 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](
|
return RA.Traverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
|
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseArrayWithIndex transforms an array
|
// 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](
|
return RA.MonadTraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
|
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -58,27 +58,27 @@ func MonadTraverseArrayWithIndex[GB ~func() ET.Either[E, B], GBS ~func() ET.Eith
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArrayWithIndex transforms an array
|
// 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](
|
return RA.TraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
|
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceArray converts a homogeneous sequence of either into an either of sequence
|
// 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])
|
return MonadTraverseArray[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseRecord transforms an array
|
// 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](
|
return RR.MonadTraverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
|
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -86,38 +86,38 @@ func MonadTraverseRecord[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E, BB
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecord transforms an array
|
// 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](
|
return RR.Traverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
|
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndex transforms an array
|
// 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](
|
return RR.TraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
Ap[GBS, func() ET.Either[E, func(B) BBS], GB],
|
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceRecord converts a homogeneous sequence of either into an either of sequence
|
// 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])
|
return MonadTraverseRecord[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseArraySeq transforms an array
|
// 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](
|
return RA.MonadTraverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -125,22 +125,22 @@ func MonadTraverseArraySeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArraySeq transforms an array
|
// 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](
|
return RA.Traverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseArrayWithIndexSeq transforms an array
|
// 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](
|
return RA.MonadTraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -148,27 +148,27 @@ func MonadTraverseArrayWithIndexSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.E
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArrayWithIndexSeq transforms an array
|
// 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](
|
return RA.TraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceArraySeq converts a homogeneous sequence of either into an either of sequence
|
// 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])
|
return MonadTraverseArraySeq[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseRecordSeq transforms an array
|
// 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](
|
return RR.MonadTraverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -176,38 +176,38 @@ func MonadTraverseRecordSeq[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordSeq transforms an array
|
// 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](
|
return RR.Traverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndexSeq transforms an array
|
// 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](
|
return RR.TraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApSeq[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceRecordSeq converts a homogeneous sequence of either into an either of sequence
|
// 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])
|
return MonadTraverseRecordSeq[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseArrayPar transforms an array
|
// 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](
|
return RA.MonadTraverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -215,22 +215,22 @@ func MonadTraverseArrayPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArrayPar transforms an array
|
// 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](
|
return RA.Traverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseArrayWithIndexPar transforms an array
|
// 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](
|
return RA.MonadTraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -238,27 +238,27 @@ func MonadTraverseArrayWithIndexPar[GB ~func() ET.Either[E, B], GBS ~func() ET.E
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseArrayWithIndexPar transforms an array
|
// 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](
|
return RA.TraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceArrayPar converts a homogeneous sequence of either into an either of sequence
|
// 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])
|
return MonadTraverseArrayPar[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonadTraverseRecordPar transforms an array
|
// 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](
|
return RR.MonadTraverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
tas,
|
tas,
|
||||||
f,
|
f,
|
||||||
@ -266,28 +266,28 @@ func MonadTraverseRecordPar[GB ~func() ET.Either[E, B], GBS ~func() ET.Either[E,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordPar transforms an array
|
// 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](
|
return RR.Traverse[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TraverseRecordWithIndexPar transforms an array
|
// 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](
|
return RR.TraverseWithIndex[AAS](
|
||||||
Of[GBS, E, BBS],
|
Of[GBS, E, BBS],
|
||||||
Map[GBS, func() ET.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
|
||||||
ApPar[GBS, func() ET.Either[E, func(B) BBS], GB],
|
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
|
||||||
|
|
||||||
f,
|
f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SequenceRecordPar converts a homogeneous sequence of either into an either of sequence
|
// 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])
|
return MonadTraverseRecordPar[GA, GAS](tas, F.Identity[GA])
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
F "github.com/IBM/fp-go/v2/function"
|
F "github.com/IBM/fp-go/v2/function"
|
||||||
R "github.com/IBM/fp-go/v2/http/builder"
|
R "github.com/IBM/fp-go/v2/http/builder"
|
||||||
H "github.com/IBM/fp-go/v2/http/headers"
|
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"
|
IOEH "github.com/IBM/fp-go/v2/ioeither/http"
|
||||||
LZ "github.com/IBM/fp-go/v2/lazy"
|
LZ "github.com/IBM/fp-go/v2/lazy"
|
||||||
O "github.com/IBM/fp-go/v2/option"
|
O "github.com/IBM/fp-go/v2/option"
|
||||||
@ -32,8 +32,8 @@ import (
|
|||||||
|
|
||||||
func Requester(builder *R.Builder) IOEH.Requester {
|
func Requester(builder *R.Builder) IOEH.Requester {
|
||||||
|
|
||||||
withBody := F.Curry3(func(data []byte, url string, method string) IOE.IOEither[error, *http.Request] {
|
withBody := F.Curry3(func(data []byte, url string, method string) ioeither.IOEither[error, *http.Request] {
|
||||||
return IOE.TryCatchError(func() (*http.Request, error) {
|
return ioeither.TryCatchError(func() (*http.Request, error) {
|
||||||
req, err := http.NewRequest(method, url, bytes.NewReader(data))
|
req, err := http.NewRequest(method, url, bytes.NewReader(data))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
req.Header.Set(H.ContentLength, strconv.Itoa(len(data)))
|
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] {
|
withoutBody := F.Curry2(func(url string, method string) ioeither.IOEither[error, *http.Request] {
|
||||||
return IOE.TryCatchError(func() (*http.Request, error) {
|
return ioeither.TryCatchError(func() (*http.Request, error) {
|
||||||
req, err := http.NewRequest(method, url, nil)
|
req, err := http.NewRequest(method, url, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
H.Monoid.Concat(req.Header, builder.GetHeaders())
|
H.Monoid.Concat(req.Header, builder.GetHeaders())
|
||||||
@ -56,10 +56,10 @@ func Requester(builder *R.Builder) IOEH.Requester {
|
|||||||
return F.Pipe5(
|
return F.Pipe5(
|
||||||
builder.GetBody(),
|
builder.GetBody(),
|
||||||
O.Fold(LZ.Of(E.Of[error](withoutBody)), E.Map[error](withBody)),
|
O.Fold(LZ.Of(E.Of[error](withoutBody)), E.Map[error](withBody)),
|
||||||
E.Ap[func(string) IOE.IOEither[error, *http.Request]](builder.GetTargetURL()),
|
E.Ap[func(string) ioeither.IOEither[error, *http.Request]](builder.GetTargetURL()),
|
||||||
E.Flap[error, IOE.IOEither[error, *http.Request]](builder.GetMethod()),
|
E.Flap[error, ioeither.IOEither[error, *http.Request]](builder.GetMethod()),
|
||||||
E.GetOrElse(IOE.Left[*http.Request, error]),
|
E.GetOrElse(ioeither.Left[*http.Request, error]),
|
||||||
IOE.Map[error](func(req *http.Request) *http.Request {
|
ioeither.Map[error](func(req *http.Request) *http.Request {
|
||||||
req.Header = H.Monoid.Concat(req.Header, builder.GetHeaders())
|
req.Header = H.Monoid.Concat(req.Header, builder.GetHeaders())
|
||||||
return req
|
return req
|
||||||
}),
|
}),
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
F "github.com/IBM/fp-go/v2/function"
|
F "github.com/IBM/fp-go/v2/function"
|
||||||
R "github.com/IBM/fp-go/v2/http/builder"
|
R "github.com/IBM/fp-go/v2/http/builder"
|
||||||
IO "github.com/IBM/fp-go/v2/io"
|
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"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,10 +42,10 @@ func TestBuilderWithQuery(t *testing.T) {
|
|||||||
req := F.Pipe3(
|
req := F.Pipe3(
|
||||||
b,
|
b,
|
||||||
Requester,
|
Requester,
|
||||||
IOE.Map[error](func(r *http.Request) *url.URL {
|
ioeither.Map[error](func(r *http.Request) *url.URL {
|
||||||
return r.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() {
|
return IO.FromImpure(func() {
|
||||||
q := u.Query()
|
q := u.Query()
|
||||||
assert.Equal(t, "10", q.Get("limit"))
|
assert.Equal(t, "10", q.Get("limit"))
|
||||||
|
@ -19,14 +19,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
DI "github.com/IBM/fp-go/v2/di"
|
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"
|
IOEH "github.com/IBM/fp-go/v2/ioeither/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// InjHttpClient is the [DI.InjectionToken] for the [http.DefaultClient]
|
// 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 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))
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
FL "github.com/IBM/fp-go/v2/file"
|
FL "github.com/IBM/fp-go/v2/file"
|
||||||
F "github.com/IBM/fp-go/v2/function"
|
F "github.com/IBM/fp-go/v2/function"
|
||||||
H "github.com/IBM/fp-go/v2/http"
|
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"
|
IOEF "github.com/IBM/fp-go/v2/ioeither/file"
|
||||||
J "github.com/IBM/fp-go/v2/json"
|
J "github.com/IBM/fp-go/v2/json"
|
||||||
P "github.com/IBM/fp-go/v2/pair"
|
P "github.com/IBM/fp-go/v2/pair"
|
||||||
@ -32,21 +32,21 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
// Requester is a reader that constructs a request
|
// Requester is a reader that constructs a request
|
||||||
Requester = IOE.IOEither[error, *http.Request]
|
Requester = ioeither.IOEither[error, *http.Request]
|
||||||
|
|
||||||
Client interface {
|
Client interface {
|
||||||
Do(Requester) IOE.IOEither[error, *http.Response]
|
Do(Requester) ioeither.IOEither[error, *http.Response]
|
||||||
}
|
}
|
||||||
|
|
||||||
client struct {
|
client struct {
|
||||||
delegate *http.Client
|
delegate *http.Client
|
||||||
doIOE func(*http.Request) IOE.IOEither[error, *http.Response]
|
doIOE func(*http.Request) ioeither.IOEither[error, *http.Response]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// MakeRequest is an eitherized version of [http.NewRequest]
|
// MakeRequest is an eitherized version of [http.NewRequest]
|
||||||
MakeRequest = IOE.Eitherize3(http.NewRequest)
|
MakeRequest = ioeither.Eitherize3(http.NewRequest)
|
||||||
makeRequest = F.Bind13of3(MakeRequest)
|
makeRequest = F.Bind13of3(MakeRequest)
|
||||||
|
|
||||||
// specialize
|
// specialize
|
||||||
@ -54,92 +54,92 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// MakeBodyRequest creates a request that carries a body
|
// 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(
|
onBody := F.Pipe1(
|
||||||
body,
|
body,
|
||||||
IOE.Map[error](F.Flow2(
|
ioeither.Map[error](F.Flow2(
|
||||||
bytes.NewReader,
|
bytes.NewReader,
|
||||||
FL.ToReader[*bytes.Reader],
|
FL.ToReader[*bytes.Reader],
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
onRelease := IOE.Of[error, io.Reader]
|
onRelease := ioeither.Of[error, io.Reader]
|
||||||
withMethod := F.Bind1of3(MakeRequest)(method)
|
withMethod := F.Bind1of3(MakeRequest)(method)
|
||||||
|
|
||||||
return F.Flow2(
|
return F.Flow2(
|
||||||
F.Bind1of2(withMethod),
|
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(
|
return F.Pipe1(
|
||||||
req,
|
req,
|
||||||
IOE.Chain(client.doIOE),
|
ioeither.Chain(client.doIOE),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeClient(httpClient *http.Client) Client {
|
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
|
// 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(
|
return F.Flow3(
|
||||||
client.Do,
|
client.Do,
|
||||||
IOE.ChainEitherK(H.ValidateResponse),
|
ioeither.ChainEitherK(H.ValidateResponse),
|
||||||
IOE.Chain(func(resp *http.Response) IOE.IOEither[error, H.FullResponse] {
|
ioeither.Chain(func(resp *http.Response) ioeither.IOEither[error, H.FullResponse] {
|
||||||
return F.Pipe1(
|
return F.Pipe1(
|
||||||
F.Pipe3(
|
F.Pipe3(
|
||||||
resp,
|
resp,
|
||||||
H.GetBody,
|
H.GetBody,
|
||||||
IOE.Of[error, io.ReadCloser],
|
ioeither.Of[error, io.ReadCloser],
|
||||||
IOEF.ReadAll[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
|
// 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(
|
return F.Flow2(
|
||||||
ReadFullResponse(client),
|
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
|
// 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(
|
return F.Flow2(
|
||||||
ReadAll(client),
|
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
|
// ReadJson sends a request, reads the response and parses the response as JSON
|
||||||
//
|
//
|
||||||
// Deprecated: use [ReadJSON] instead
|
// 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)
|
return ReadJSON[A](client)
|
||||||
}
|
}
|
||||||
|
|
||||||
// readJSON sends a request, reads the response and parses the response as a []byte
|
// 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(
|
return F.Flow3(
|
||||||
ReadFullResponse(client),
|
ReadFullResponse(client),
|
||||||
IOE.ChainFirstEitherK(F.Flow2(
|
ioeither.ChainFirstEitherK(F.Flow2(
|
||||||
H.Response,
|
H.Response,
|
||||||
H.ValidateJSONResponse,
|
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
|
// 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(
|
return F.Flow2(
|
||||||
readJSON(client),
|
readJSON(client),
|
||||||
IOE.ChainEitherK[error](J.Unmarshal[A]),
|
ioeither.ChainEitherK[error](J.Unmarshal[A]),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
E "github.com/IBM/fp-go/v2/either"
|
E "github.com/IBM/fp-go/v2/either"
|
||||||
"github.com/IBM/fp-go/v2/errors"
|
"github.com/IBM/fp-go/v2/errors"
|
||||||
F "github.com/IBM/fp-go/v2/function"
|
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"
|
O "github.com/IBM/fp-go/v2/option"
|
||||||
R "github.com/IBM/fp-go/v2/retry"
|
R "github.com/IBM/fp-go/v2/retry"
|
||||||
"github.com/stretchr/testify/assert"
|
"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")
|
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{})
|
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(
|
return F.Pipe1(
|
||||||
MakeGetRequest(urls[status.IterNumber]),
|
MakeGetRequest(urls[status.IterNumber]),
|
||||||
ReadJSON[*PostItem](client),
|
ReadJSON[*PostItem](client),
|
||||||
@ -66,6 +66,6 @@ func TestRetryHttp(t *testing.T) {
|
|||||||
F.Constant1[*PostItem](false),
|
F.Constant1[*PostItem](false),
|
||||||
)
|
)
|
||||||
|
|
||||||
item := IOE.Retrying(testLogPolicy, action, check)()
|
item := ioeither.Retrying(testLogPolicy, action, check)()
|
||||||
assert.True(t, E.IsRight(item))
|
assert.True(t, E.IsRight(item))
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
package ioeither
|
package ioeither
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ET "github.com/IBM/fp-go/v2/either"
|
"github.com/IBM/fp-go/v2/either"
|
||||||
G "github.com/IBM/fp-go/v2/ioeither/generic"
|
"github.com/IBM/fp-go/v2/io"
|
||||||
R "github.com/IBM/fp-go/v2/retry"
|
R "github.com/IBM/fp-go/v2/retry"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ import (
|
|||||||
func Retrying[E, A any](
|
func Retrying[E, A any](
|
||||||
policy R.RetryPolicy,
|
policy R.RetryPolicy,
|
||||||
action func(R.RetryStatus) IOEither[E, A],
|
action func(R.RetryStatus) IOEither[E, A],
|
||||||
check func(ET.Either[E, A]) bool,
|
check func(either.Either[E, A]) bool,
|
||||||
) IOEither[E, A] {
|
) IOEither[E, A] {
|
||||||
return G.Retrying(policy, action, check)
|
return io.Retrying(policy, action, check)
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ package testing
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
ET "github.com/IBM/fp-go/v2/either"
|
"github.com/IBM/fp-go/v2/either"
|
||||||
EQ "github.com/IBM/fp-go/v2/eq"
|
EQ "github.com/IBM/fp-go/v2/eq"
|
||||||
L "github.com/IBM/fp-go/v2/internal/monad/testing"
|
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
|
// 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 {
|
) func(a A) bool {
|
||||||
|
|
||||||
return L.AssertLaws(t,
|
return L.AssertLaws(t,
|
||||||
IOE.Eq(ET.Eq(eqe, eqa)),
|
ioeither.Eq(either.Eq(eqe, eqa)),
|
||||||
IOE.Eq(ET.Eq(eqe, eqb)),
|
ioeither.Eq(either.Eq(eqe, eqb)),
|
||||||
IOE.Eq(ET.Eq(eqe, eqc)),
|
ioeither.Eq(either.Eq(eqe, eqc)),
|
||||||
|
|
||||||
IOE.Of[E, A],
|
ioeither.Of[E, A],
|
||||||
IOE.Of[E, B],
|
ioeither.Of[E, B],
|
||||||
IOE.Of[E, C],
|
ioeither.Of[E, C],
|
||||||
|
|
||||||
IOE.Of[E, func(A) A],
|
ioeither.Of[E, func(A) A],
|
||||||
IOE.Of[E, func(A) B],
|
ioeither.Of[E, func(A) B],
|
||||||
IOE.Of[E, func(B) C],
|
ioeither.Of[E, func(B) C],
|
||||||
IOE.Of[E, func(func(A) B) B],
|
ioeither.Of[E, func(func(A) B) B],
|
||||||
|
|
||||||
IOE.MonadMap[E, A, A],
|
ioeither.MonadMap[E, A, A],
|
||||||
IOE.MonadMap[E, A, B],
|
ioeither.MonadMap[E, A, B],
|
||||||
IOE.MonadMap[E, A, C],
|
ioeither.MonadMap[E, A, C],
|
||||||
IOE.MonadMap[E, B, 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],
|
ioeither.MonadChain[E, A, A],
|
||||||
IOE.MonadChain[E, A, B],
|
ioeither.MonadChain[E, A, B],
|
||||||
IOE.MonadChain[E, A, C],
|
ioeither.MonadChain[E, A, C],
|
||||||
IOE.MonadChain[E, B, C],
|
ioeither.MonadChain[E, B, C],
|
||||||
|
|
||||||
IOE.MonadAp[A, E, A],
|
ioeither.MonadAp[A, E, A],
|
||||||
IOE.MonadAp[B, E, A],
|
ioeither.MonadAp[B, E, A],
|
||||||
IOE.MonadAp[C, E, B],
|
ioeither.MonadAp[C, E, B],
|
||||||
IOE.MonadAp[C, E, A],
|
ioeither.MonadAp[C, E, A],
|
||||||
|
|
||||||
IOE.MonadAp[B, E, func(A) B],
|
ioeither.MonadAp[B, E, func(A) B],
|
||||||
IOE.MonadAp[func(A) C, E, func(A) B],
|
ioeither.MonadAp[func(A) C, E, func(A) B],
|
||||||
|
|
||||||
ab,
|
ab,
|
||||||
bc,
|
bc,
|
||||||
|
Reference in New Issue
Block a user