1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-11-25 22:21:49 +02:00

fix: next step in migration

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2025-03-04 21:59:09 +01:00
parent 8a4ecd2203
commit 4d008e636a
49 changed files with 1039 additions and 1493 deletions

View File

@@ -15,7 +15,9 @@
package array package array
import "github.com/IBM/fp-go/v2/internal/array" import (
"github.com/IBM/fp-go/v2/internal/array"
)
func Traverse[A, B, HKTB, HKTAB, HKTRB any]( func Traverse[A, B, HKTB, HKTAB, HKTRB any](
fof func([]B) HKTRB, fof func([]B) HKTRB,

View File

@@ -16,10 +16,18 @@
package readerioeither package readerioeither
import ( import (
G "github.com/IBM/fp-go/v2/context/readerioeither/generic" "context"
CIOE "github.com/IBM/fp-go/v2/context/ioeither/generic"
"github.com/IBM/fp-go/v2/ioeither"
) )
// WithContext wraps an existing [ReaderIOEither] and performs a context check for cancellation before delegating // WithContext wraps an existing [ReaderIOEither] and performs a context check for cancellation before delegating
func WithContext[A any](ma ReaderIOEither[A]) ReaderIOEither[A] { func WithContext[A any](ma ReaderIOEither[A]) ReaderIOEither[A] {
return G.WithContext(ma) return func(ctx context.Context) ioeither.IOEither[error, A] {
if err := context.Cause(ctx); err != nil {
return ioeither.Left[A](err)
}
return CIOE.WithContext(ctx, ma(ctx))
}
} }

View File

@@ -56,9 +56,9 @@ func Close[C io.Closer](c C) RIOE.ReaderIOEither[any] {
func ReadFile(path string) RIOE.ReaderIOEither[[]byte] { func ReadFile(path string) RIOE.ReaderIOEither[[]byte] {
return RIOE.WithResource[[]byte](Open(path), Close[*os.File])(func(r *os.File) RIOE.ReaderIOEither[[]byte] { return RIOE.WithResource[[]byte](Open(path), Close[*os.File])(func(r *os.File) RIOE.ReaderIOEither[[]byte] {
return func(ctx context.Context) IOE.IOEither[error, []byte] { return func(ctx context.Context) IOE.IOEither[error, []byte] {
return IOE.MakeIO(func() ET.Either[error, []byte] { return func() ET.Either[error, []byte] {
return file.ReadAll(ctx, r) return file.ReadAll(ctx, r)
}) }
} }
}) })
} }

View File

@@ -1,40 +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"
E "github.com/IBM/fp-go/v2/either"
F "github.com/IBM/fp-go/v2/function"
RIE "github.com/IBM/fp-go/v2/readerioeither/generic"
)
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource
func WithResource[
GRA ~func(context.Context) GIOA,
GRR ~func(context.Context) GIOR,
GRANY ~func(context.Context) GIOANY,
GIOR ~func() E.Either[error, R],
GIOA ~func() E.Either[error, A],
GIOANY ~func() E.Either[error, ANY],
R, A, ANY any](onCreate GRR, onRelease func(R) GRANY) func(func(R) GRA) GRA {
// wraps the callback functions with a context check
return F.Flow2(
F.Bind2nd(F.Flow2[func(R) GRA, func(GRA) GRA, R, GRA, GRA], WithContext[GRA]),
RIE.WithResource[GRA](WithContext(onCreate), onRelease),
)
}

View File

@@ -1,44 +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"
E "github.com/IBM/fp-go/v2/either"
F "github.com/IBM/fp-go/v2/function"
IO "github.com/IBM/fp-go/v2/io/generic"
)
// WithLock executes the provided IO operation in the scope of a lock
func WithLock[
GRA ~func(context.Context) GIOA,
GIOA ~func() E.Either[error, A],
GRCANCEL ~func(context.Context) GIOCANCEL,
GIOCANCEL ~func() E.Either[error, context.CancelFunc],
A any](lock GRCANCEL) func(fa GRA) GRA {
type GRANY func(ctx context.Context) func() E.Either[error, any]
type IOANY func() any
return F.Flow2(
F.Constant1[context.CancelFunc, GRA],
WithResource[GRA, GRCANCEL, GRANY](lock, F.Flow2(
IO.FromImpure[IOANY, context.CancelFunc],
FromIO[GRANY, IOANY],
)),
)
}

View File

@@ -16,11 +16,16 @@
package readerioeither package readerioeither
import ( import (
G "github.com/IBM/fp-go/v2/context/readerioeither/generic" "context"
"github.com/IBM/fp-go/v2/function"
RIE "github.com/IBM/fp-go/v2/readerioeither"
) )
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource // WithResource constructs a function that creates a resource, then operates on it and then releases the resource
func WithResource[A, R, ANY any](onCreate ReaderIOEither[R], onRelease func(R) ReaderIOEither[ANY]) func(func(R) ReaderIOEither[A]) ReaderIOEither[A] { func WithResource[A, R, ANY any](onCreate ReaderIOEither[R], onRelease func(R) ReaderIOEither[ANY]) func(func(R) ReaderIOEither[A]) ReaderIOEither[A] {
// wraps the callback functions with a context check return function.Flow2(
return G.WithResource[ReaderIOEither[A]](onCreate, onRelease) function.Bind2nd(function.Flow2[func(R) ReaderIOEither[A], func(ReaderIOEither[A]) ReaderIOEither[A], R, ReaderIOEither[A], ReaderIOEither[A]], WithContext[A]),
RIE.WithResource[A, context.Context, error, R](WithContext(onCreate), onRelease),
)
} }

View File

@@ -18,10 +18,17 @@ package readerioeither
import ( import (
"context" "context"
G "github.com/IBM/fp-go/v2/context/readerioeither/generic" "github.com/IBM/fp-go/v2/function"
"github.com/IBM/fp-go/v2/io"
) )
// WithLock executes the provided IO operation in the scope of a lock // WithLock executes the provided IO operation in the scope of a lock
func WithLock[A any](lock ReaderIOEither[context.CancelFunc]) func(fa ReaderIOEither[A]) ReaderIOEither[A] { func WithLock[A any](lock ReaderIOEither[context.CancelFunc]) func(fa ReaderIOEither[A]) ReaderIOEither[A] {
return G.WithLock[ReaderIOEither[A]](lock) return function.Flow2(
function.Constant1[context.CancelFunc, ReaderIOEither[A]],
WithResource[A](lock, function.Flow2(
io.FromImpure[context.CancelFunc],
FromIO[any],
)),
)
} }

View File

@@ -23,4 +23,4 @@ import (
// ReaderIOEither is a specialization of the [RE.ReaderIOEither] monad for the typical golang scenario in which the // ReaderIOEither is a specialization of the [RE.ReaderIOEither] monad for the typical golang scenario in which the
// left value is an [error] and the context is a [context.Context] // left value is an [error] and the context is a [context.Context]
type ReaderIOEither[A any] RE.ReaderIOEither[context.Context, error, A] type ReaderIOEither[A any] = RE.ReaderIOEither[context.Context, error, A]

View File

@@ -1,101 +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 (
A "github.com/IBM/fp-go/v2/internal/apply"
C "github.com/IBM/fp-go/v2/internal/chain"
F "github.com/IBM/fp-go/v2/internal/functor"
)
// Bind creates an empty context of type [S] to be used with the [Bind] operation
//
// Deprecated:
func Do[GS ~func() S, S any](
empty S,
) GS {
return Of[GS](empty)
}
// Bind attaches the result of a computation to a context [S1] to produce a context [S2]
//
// Deprecated:
func Bind[GS1 ~func() S1, GS2 ~func() S2, GT ~func() T, S1, S2, T any](
setter func(T) func(S1) S2,
f func(S1) GT,
) func(GS1) GS2 {
return C.Bind(
Chain[GS1, GS2, S1, S2],
Map[GT, GS2, T, S2],
setter,
f,
)
}
// Let attaches the result of a computation to a context [S1] to produce a context [S2]
//
// Deprecated:
func Let[GS1 ~func() S1, GS2 ~func() S2, S1, S2, T any](
key func(T) func(S1) S2,
f func(S1) T,
) func(GS1) GS2 {
return F.Let(
Map[GS1, GS2, S1, S2],
key,
f,
)
}
// LetTo attaches the a value to a context [S1] to produce a context [S2]
//
// Deprecated:
func LetTo[GS1 ~func() S1, GS2 ~func() S2, S1, S2, B any](
key func(B) func(S1) S2,
b B,
) func(GS1) GS2 {
return F.LetTo(
Map[GS1, GS2, S1, S2],
key,
b,
)
}
// BindTo initializes a new state [S1] from a value [T]
//
// Deprecated:
func BindTo[GS1 ~func() S1, GT ~func() T, S1, T any](
setter func(T) S1,
) func(GT) GS1 {
return C.BindTo(
Map[GT, GS1, T, S1],
setter,
)
}
// ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently
//
// Deprecated:
func ApS[GS1 ~func() S1, GS2 ~func() S2, GT ~func() T, S1, S2, T any](
setter func(T) func(S1) S2,
fa GT,
) func(GS1) GS2 {
return A.ApS(
Ap[GS2, func() func(T) S2, GT, S2, T],
Map[GS1, func() func(T) S2, S1, func(T) S2],
setter,
fa,
)
}

View File

@@ -58,7 +58,7 @@ func FromIO[A any](a IO[A]) IO[A] {
} }
// 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
func FromImpure(f func()) IO[any] { func FromImpure[ANY ~func()](f ANY) IO[any] {
return func() any { return func() any {
f() f()
return undefined return undefined

View File

@@ -16,25 +16,47 @@
package ioeither package ioeither
import ( import (
G "github.com/IBM/fp-go/v2/ioeither/generic" "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[A, E, B any](first IOEither[E, A], second IOEither[E, B]) IOEither[E, A] { func MonadApFirst[A, E, B any](first IOEither[E, A], second IOEither[E, B]) IOEither[E, A] {
return G.MonadApFirst[IOEither[E, A], IOEither[E, B], IOEither[E, func(B) A]](first, second) return apply.MonadApFirst(
MonadAp[A, E, B],
MonadMap[E, A, func(B) A],
first,
second,
)
} }
// 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[A, E, B any](second IOEither[E, B]) func(IOEither[E, A]) IOEither[E, A] { func ApFirst[A, E, B any](second IOEither[E, B]) Mapper[E, A, A] {
return G.ApFirst[IOEither[E, A], IOEither[E, B], IOEither[E, func(B) A]](second) return apply.ApFirst(
MonadAp[A, E, B],
MonadMap[E, A, func(B) A],
second,
)
} }
// 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[A, E, B any](first IOEither[E, A], second IOEither[E, B]) IOEither[E, B] { func MonadApSecond[A, E, B any](first IOEither[E, A], second IOEither[E, B]) IOEither[E, B] {
return G.MonadApSecond[IOEither[E, A], IOEither[E, B], IOEither[E, func(B) B]](first, second) return apply.MonadApSecond(
MonadAp[B, E, B],
MonadMap[E, A, func(B) B],
first,
second,
)
} }
// 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[A, E, B any](second IOEither[E, B]) func(IOEither[E, A]) IOEither[E, B] { func ApSecond[A, E, B any](second IOEither[E, B]) Mapper[E, A, B] {
return G.ApSecond[IOEither[E, A], IOEither[E, B], IOEither[E, func(B) B]](second) return apply.ApSecond(
MonadAp[B, E, B],
MonadMap[E, A, func(B) B],
second,
)
} }

View File

@@ -16,51 +16,74 @@
package ioeither package ioeither
import ( import (
G "github.com/IBM/fp-go/v2/ioeither/generic" "github.com/IBM/fp-go/v2/internal/apply"
"github.com/IBM/fp-go/v2/internal/chain"
"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[E, S any]( func Do[E, S any](
empty S, empty S,
) IOEither[E, S] { ) IOEither[E, S] {
return G.Do[IOEither[E, S], E, S](empty) return Of[E](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[E, S1, S2, T any]( func Bind[E, S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
f func(S1) IOEither[E, T], f func(S1) IOEither[E, T],
) func(IOEither[E, S1]) IOEither[E, S2] { ) Mapper[E, S1, S2] {
return G.Bind[IOEither[E, S1], IOEither[E, S2], IOEither[E, T], E, S1, S2, T](setter, f) return chain.Bind(
Chain[E, S1, S2],
Map[E, T, S2],
setter,
f,
)
} }
// 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[E, S1, S2, T any]( func Let[E, S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
f func(S1) T, f func(S1) T,
) func(IOEither[E, S1]) IOEither[E, S2] { ) Mapper[E, S1, S2] {
return G.Let[IOEither[E, S1], IOEither[E, S2], E, S1, S2, T](setter, f) return functor.Let(
Map[E, S1, S2],
setter,
f,
)
} }
// 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[E, S1, S2, T any]( func LetTo[E, S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
b T, b T,
) func(IOEither[E, S1]) IOEither[E, S2] { ) Mapper[E, S1, S2] {
return G.LetTo[IOEither[E, S1], IOEither[E, S2], E, S1, S2, T](setter, b) return functor.LetTo(
Map[E, S1, S2],
setter,
b,
)
} }
// BindTo initializes a new state [S1] from a value [T] // BindTo initializes a new state [S1] from a value [T]
func BindTo[E, S1, T any]( func BindTo[E, S1, T any](
setter func(T) S1, setter func(T) S1,
) func(IOEither[E, T]) IOEither[E, S1] { ) Mapper[E, T, S1] {
return G.BindTo[IOEither[E, S1], IOEither[E, T], E, S1, T](setter) return chain.BindTo(
Map[E, T, S1],
setter,
)
} }
// 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[E, S1, S2, T any]( func ApS[E, S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
fa IOEither[E, T], fa IOEither[E, T],
) func(IOEither[E, S1]) IOEither[E, S2] { ) Mapper[E, S1, S2] {
return G.ApS[IOEither[E, S1], IOEither[E, S2], IOEither[E, T], E, S1, S2, T](setter, fa) return apply.ApS(
Ap[S2, E, T],
Map[E, S1, func(T) S2],
setter,
fa,
)
} }

View File

@@ -16,7 +16,6 @@
package ioeither package ioeither
import ( import (
"github.com/IBM/fp-go/v2/either"
BR "github.com/IBM/fp-go/v2/internal/bracket" BR "github.com/IBM/fp-go/v2/internal/bracket"
"github.com/IBM/fp-go/v2/io" "github.com/IBM/fp-go/v2/io"
) )
@@ -26,12 +25,12 @@ 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, either.Either[E, B]) IOEither[E, ANY], release func(A, Either[E, B]) IOEither[E, ANY],
) IOEither[E, B] { ) IOEither[E, B] {
return BR.Bracket[IOEither[E, A], IOEither[E, B], IOEither[E, ANY], either.Either[E, B], A, B]( return BR.Bracket[IOEither[E, A], IOEither[E, B], IOEither[E, ANY], Either[E, B], A, B](
io.Of[either.Either[E, B]], io.Of[Either[E, B]],
MonadChain[E, A, B], MonadChain[E, A, B],
io.MonadChain[either.Either[E, B], either.Either[E, B]], io.MonadChain[Either[E, B], Either[E, B]],
MonadChain[E, ANY, B], MonadChain[E, ANY, B],
acquire, acquire,

View File

@@ -18,12 +18,12 @@ package ioeither
import ( import (
"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" "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[either.Either[E, A]]) EQ.Eq[IOEither[E, A]] { func Eq[E, A any](eq EQ.Eq[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

View File

@@ -20,7 +20,7 @@ import (
"log" "log"
F "github.com/IBM/fp-go/v2/function" F "github.com/IBM/fp-go/v2/function"
IO "github.com/IBM/fp-go/v2/io" "github.com/IBM/fp-go/v2/io"
T "github.com/IBM/fp-go/v2/tuple" T "github.com/IBM/fp-go/v2/tuple"
) )
@@ -29,8 +29,8 @@ func ExampleIOEither_do() {
bar := Of[error](1) bar := Of[error](1)
// quux consumes the state of three bindings and returns an [IO] instead of an [IOEither] // quux consumes the state of three bindings and returns an [IO] instead of an [IOEither]
quux := func(t T.Tuple3[string, int, string]) IO.IO[any] { quux := func(t T.Tuple3[string, int, string]) IO[any] {
return IO.FromImpure(func() { return io.FromImpure(func() {
log.Printf("t1: %s, t2: %d, t3: %s", t.F1, t.F2, t.F3) log.Printf("t1: %s, t2: %d, t3: %s", t.F1, t.F2, t.F3)
}) })
} }

View File

@@ -20,7 +20,7 @@ import (
E "github.com/IBM/fp-go/v2/either" E "github.com/IBM/fp-go/v2/either"
F "github.com/IBM/fp-go/v2/function" F "github.com/IBM/fp-go/v2/function"
IO "github.com/IBM/fp-go/v2/io" "github.com/IBM/fp-go/v2/io"
) )
func ExampleIOEither_extraction() { func ExampleIOEither_extraction() {
@@ -30,7 +30,7 @@ func ExampleIOEither_extraction() {
value := E.GetOrElse(F.Constant1[error](0))(eitherValue) // 42 value := E.GetOrElse(F.Constant1[error](0))(eitherValue) // 42
// Or more directly // Or more directly
infaillibleIO := GetOrElse(F.Constant1[error](IO.Of(0)))(someIOEither) // => IO.Right(42) infaillibleIO := GetOrElse(F.Constant1[error](io.Of(0)))(someIOEither) // => io.Right(42)
valueFromIO := infaillibleIO() // => 42 valueFromIO := infaillibleIO() // => 42
fmt.Println(eitherValue) fmt.Println(eitherValue)

View File

@@ -19,14 +19,14 @@ import (
"context" "context"
"github.com/IBM/fp-go/v2/exec" "github.com/IBM/fp-go/v2/exec"
F "github.com/IBM/fp-go/v2/function" "github.com/IBM/fp-go/v2/function"
INTE "github.com/IBM/fp-go/v2/internal/exec" INTE "github.com/IBM/fp-go/v2/internal/exec"
"github.com/IBM/fp-go/v2/ioeither" "github.com/IBM/fp-go/v2/ioeither"
) )
var ( var (
// Command executes a command // Command executes a command
Command = F.Curry3(command) Command = function.Curry3(command)
) )
func command(name string, args []string, in []byte) ioeither.IOEither[error, exec.CommandOutput] { func command(name string, args []string, in []byte) ioeither.IOEither[error, exec.CommandOutput] {

View File

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

View File

@@ -1,63 +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 (
"github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/internal/apply"
)
// MonadApFirst combines two effectful actions, keeping only the result of the first.
func MonadApFirst[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBA ~func() either.Either[E, func(B) A], E, A, B any](first GA, second GB) GA {
return G.MonadApFirst(
MonadAp[GA, GBA, GB],
MonadMap[GA, GBA, E, A, func(B) A],
first,
second,
)
}
// ApFirst combines two effectful actions, keeping only the result of the first.
func ApFirst[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBA ~func() either.Either[E, func(B) A], E, A, B any](second GB) func(GA) GA {
return G.ApFirst(
MonadAp[GA, GBA, GB],
MonadMap[GA, GBA, E, A, func(B) A],
second,
)
}
// MonadApSecond combines two effectful actions, keeping only the result of the second.
func MonadApSecond[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBB ~func() either.Either[E, func(B) B], E, A, B any](first GA, second GB) GB {
return G.MonadApSecond(
MonadAp[GB, GBB, GB],
MonadMap[GA, GBB, E, A, func(B) B],
first,
second,
)
}
// ApSecond combines two effectful actions, keeping only the result of the second.
func ApSecond[GA ~func() either.Either[E, A], GB ~func() either.Either[E, B], GBB ~func() either.Either[E, func(B) B], E, A, B any](second GB) func(GA) GB {
return G.ApSecond(
MonadAp[GB, GBB, GB],
MonadMap[GA, GBB, E, A, func(B) B],
second,
)
}

View File

@@ -1,90 +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 (
"github.com/IBM/fp-go/v2/either"
A "github.com/IBM/fp-go/v2/internal/apply"
C "github.com/IBM/fp-go/v2/internal/chain"
F "github.com/IBM/fp-go/v2/internal/functor"
)
// Bind creates an empty context of type [S] to be used with the [Bind] operation
func Do[GS ~func() either.Either[E, S], E, S any](
empty S,
) GS {
return Of[GS, E, S](empty)
}
// Bind attaches the result of a computation to a context [S1] to produce a context [S2]
func Bind[GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], GT ~func() either.Either[E, T], E, S1, S2, T any](
setter func(T) func(S1) S2,
f func(S1) GT,
) func(GS1) GS2 {
return C.Bind(
Chain[GS1, GS2, E, S1, S2],
Map[GT, GS2, E, T, S2],
setter,
f,
)
}
// Let attaches the result of a computation to a context [S1] to produce a context [S2]
func Let[GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], E, S1, S2, T any](
key func(T) func(S1) S2,
f func(S1) T,
) func(GS1) GS2 {
return F.Let(
Map[GS1, GS2, E, S1, S2],
key,
f,
)
}
// LetTo attaches the a value to a context [S1] to produce a context [S2]
func LetTo[GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], E, S1, S2, B any](
key func(B) func(S1) S2,
b B,
) func(GS1) GS2 {
return F.LetTo(
Map[GS1, GS2, E, S1, S2],
key,
b,
)
}
// BindTo initializes a new state [S1] from a value [T]
func BindTo[GS1 ~func() either.Either[E, S1], GT ~func() either.Either[E, T], E, S1, S2, T any](
setter func(T) S1,
) func(GT) GS1 {
return C.BindTo(
Map[GT, GS1, E, T, S1],
setter,
)
}
// 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() either.Either[E, S1], GS2 ~func() either.Either[E, S2], GT ~func() either.Either[E, T], E, S1, S2, T any](
setter func(T) func(S1) S2,
fa GT,
) func(GS1) GS2 {
return A.ApS(
Ap[GS2, func() either.Either[E, func(T) S2], GT, E, T, S2],
Map[GS1, func() either.Either[E, func(T) S2], E, S1, func(T) S2],
setter,
fa,
)
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,293 +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 (
"github.com/IBM/fp-go/v2/either"
F "github.com/IBM/fp-go/v2/function"
RA "github.com/IBM/fp-go/v2/internal/array"
RR "github.com/IBM/fp-go/v2/internal/record"
)
// MonadTraverseArray transforms an array
func MonadTraverseArray[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
return RA.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseArray transforms an array
func TraverseArray[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
return RA.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// MonadTraverseArrayWithIndex transforms an array
func MonadTraverseArrayWithIndex[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
return RA.MonadTraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseArrayWithIndex transforms an array
func TraverseArrayWithIndex[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
return RA.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceArray converts a homogeneous sequence of either into an either of sequence
func SequenceArray[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
return MonadTraverseArray[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseRecord transforms an array
func MonadTraverseRecord[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
return RR.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseRecord transforms an array
func TraverseRecord[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
return RR.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// TraverseRecordWithIndex transforms an array
func TraverseRecordWithIndex[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
return RR.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
Ap[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceRecord converts a homogeneous sequence of either into an either of sequence
func SequenceRecord[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
return MonadTraverseRecord[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseArraySeq transforms an array
func MonadTraverseArraySeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
return RA.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseArraySeq transforms an array
func TraverseArraySeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
return RA.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// MonadTraverseArrayWithIndexSeq transforms an array
func MonadTraverseArrayWithIndexSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
return RA.MonadTraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseArrayWithIndexSeq transforms an array
func TraverseArrayWithIndexSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
return RA.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceArraySeq converts a homogeneous sequence of either into an either of sequence
func SequenceArraySeq[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
return MonadTraverseArraySeq[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseRecordSeq transforms an array
func MonadTraverseRecordSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
return RR.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseRecordSeq transforms an array
func TraverseRecordSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
return RR.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// TraverseRecordWithIndexSeq transforms an array
func TraverseRecordWithIndexSeq[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
return RR.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApSeq[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceRecordSeq converts a homogeneous sequence of either into an either of sequence
func SequenceRecordSeq[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
return MonadTraverseRecordSeq[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseArrayPar transforms an array
func MonadTraverseArrayPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(A) GB) GBS {
return RA.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseArrayPar transforms an array
func TraverseArrayPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(A) GB) func(AAS) GBS {
return RA.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// MonadTraverseArrayWithIndexPar transforms an array
func MonadTraverseArrayWithIndexPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](tas AAS, f func(int, A) GB) GBS {
return RA.MonadTraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseArrayWithIndexPar transforms an array
func TraverseArrayWithIndexPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~[]A, BBS ~[]B, E, A, B any](f func(int, A) GB) func(AAS) GBS {
return RA.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceArrayPar converts a homogeneous sequence of either into an either of sequence
func SequenceArrayPar[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~[]A, GAAS ~[]GA, E, A any](tas GAAS) GAS {
return MonadTraverseArrayPar[GA, GAS](tas, F.Identity[GA])
}
// MonadTraverseRecordPar transforms an array
func MonadTraverseRecordPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](tas AAS, f func(A) GB) GBS {
return RR.MonadTraverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
tas,
f,
)
}
// TraverseRecordPar transforms an array
func TraverseRecordPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(A) GB) func(AAS) GBS {
return RR.Traverse[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// TraverseRecordWithIndexPar transforms an array
func TraverseRecordWithIndexPar[GB ~func() either.Either[E, B], GBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, E, A, B any](f func(K, A) GB) func(AAS) GBS {
return RR.TraverseWithIndex[AAS](
Of[GBS, E, BBS],
Map[GBS, func() either.Either[E, func(B) BBS], E, BBS, func(B) BBS],
ApPar[GBS, func() either.Either[E, func(B) BBS], GB],
f,
)
}
// SequenceRecordPar converts a homogeneous sequence of either into an either of sequence
func SequenceRecordPar[GA ~func() either.Either[E, A], GAS ~func() either.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, E, A any](tas GAAS) GAS {
return MonadTraverseRecordPar[GA, GAS](tas, F.Identity[GA])
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) 2025 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 "github.com/IBM/fp-go/v2/either"
type (
Either[E, A any] = either.Either[E, A]
)

View File

@@ -32,7 +32,7 @@ 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) ioeither.IOEither[error, *http.Request] { withBody := F.Curry3(func(data []byte, url string, method string) IOEither[*http.Request] {
return ioeither.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 {
@@ -43,7 +43,7 @@ func Requester(builder *R.Builder) IOEH.Requester {
}) })
}) })
withoutBody := F.Curry2(func(url string, method string) ioeither.IOEither[error, *http.Request] { withoutBody := F.Curry2(func(url string, method string) IOEither[*http.Request] {
return ioeither.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 {
@@ -56,8 +56,8 @@ 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) ioeither.IOEither[error, *http.Request]](builder.GetTargetURL()), E.Ap[func(string) IOEither[*http.Request]](builder.GetTargetURL()),
E.Flap[error, ioeither.IOEither[error, *http.Request]](builder.GetMethod()), E.Flap[error, IOEither[*http.Request]](builder.GetMethod()),
E.GetOrElse(ioeither.Left[*http.Request, error]), E.GetOrElse(ioeither.Left[*http.Request, error]),
ioeither.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())

View File

@@ -23,7 +23,7 @@ import (
E "github.com/IBM/fp-go/v2/either" E "github.com/IBM/fp-go/v2/either"
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" "github.com/IBM/fp-go/v2/io"
"github.com/IBM/fp-go/v2/ioeither" "github.com/IBM/fp-go/v2/ioeither"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@@ -45,8 +45,8 @@ func TestBuilderWithQuery(t *testing.T) {
ioeither.Map[error](func(r *http.Request) *url.URL { ioeither.Map[error](func(r *http.Request) *url.URL {
return r.URL return r.URL
}), }),
ioeither.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"))
assert.Equal(t, "b", q.Get("a")) assert.Equal(t, "b", q.Get("a"))

View File

@@ -0,0 +1,22 @@
// Copyright (c) 2025 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 builder
import "github.com/IBM/fp-go/v2/ioeither"
type (
IOEither[A any] = ioeither.IOEither[error, A]
)

View File

@@ -34,19 +34,22 @@ import (
) )
type ( type (
IO[A any] = io.IO[A]
Either[E, A any] = either.Either[E, A]
// IOEither represents a synchronous computation that may fail // IOEither represents a synchronous computation that may fail
// refer to [https://andywhite.xyz/posts/2021-01-27-rte-foundations/#ioeitherlte-agt] for more details // refer to [https://andywhite.xyz/posts/2021-01-27-rte-foundations/#ioeitherlte-agt] for more details
IOEither[E, A any] = io.IO[either.Either[E, A]] IOEither[E, A any] = IO[Either[E, A]]
Mapper[E, A, B any] = R.Reader[IOEither[E, A], IOEither[E, B]] Mapper[E, A, B any] = R.Reader[IOEither[E, A], IOEither[E, B]]
) )
func Left[A, E any](l E) IOEither[E, A] { func Left[A, E any](l E) IOEither[E, A] {
return eithert.Left(io.MonadOf[either.Either[E, A]], l) return eithert.Left(io.MonadOf[Either[E, A]], l)
} }
func Right[E, A any](r A) IOEither[E, A] { func Right[E, A any](r A) IOEither[E, A] {
return eithert.Right(io.MonadOf[either.Either[E, A]], r) return eithert.Right(io.MonadOf[Either[E, A]], r)
} }
func Of[E, A any](r A) IOEither[E, A] { func Of[E, A any](r A) IOEither[E, A] {
@@ -57,15 +60,15 @@ func MonadOf[E, A any](r A) IOEither[E, A] {
return Of[E](r) return Of[E](r)
} }
func LeftIO[A, E any](ml io.IO[E]) IOEither[E, A] { func LeftIO[A, E any](ml IO[E]) IOEither[E, A] {
return eithert.LeftF(io.MonadMap[E, either.Either[E, A]], ml) return eithert.LeftF(io.MonadMap[E, Either[E, A]], ml)
} }
func RightIO[E, A any](mr io.IO[A]) IOEither[E, A] { func RightIO[E, A any](mr IO[A]) IOEither[E, A] {
return eithert.RightF(io.MonadMap[A, either.Either[E, A]], mr) return eithert.RightF(io.MonadMap[A, Either[E, A]], mr)
} }
func FromEither[E, A any](e either.Either[E, A]) IOEither[E, A] { func FromEither[E, A any](e Either[E, A]) IOEither[E, A] {
return io.Of(e) return io.Of(e)
} }
@@ -88,7 +91,7 @@ func ChainOptionK[A, B, E any](onNone func() E) func(func(A) O.Option[B]) func(I
) )
} }
func MonadChainIOK[E, A, B any](ma IOEither[E, A], f func(A) io.IO[B]) IOEither[E, B] { func MonadChainIOK[E, A, B any](ma IOEither[E, A], f func(A) IO[B]) IOEither[E, B] {
return fromio.MonadChainIOK( return fromio.MonadChainIOK(
MonadChain[E, A, B], MonadChain[E, A, B],
FromIO[E, B], FromIO[E, B],
@@ -97,7 +100,7 @@ func MonadChainIOK[E, A, B any](ma IOEither[E, A], f func(A) io.IO[B]) IOEither[
) )
} }
func ChainIOK[E, A, B any](f func(A) io.IO[B]) func(IOEither[E, A]) IOEither[E, B] { func ChainIOK[E, A, B any](f func(A) IO[B]) func(IOEither[E, A]) IOEither[E, B] {
return fromio.ChainIOK( return fromio.ChainIOK(
Chain[E, A, B], Chain[E, A, B],
FromIO[E, B], FromIO[E, B],
@@ -110,7 +113,7 @@ func ChainLazyK[E, A, B any](f func(A) lazy.Lazy[B]) func(IOEither[E, A]) IOEith
} }
// FromIO creates an [IOEither] from an [IO] instance, invoking [IO] for each invocation of [IOEither] // FromIO creates an [IOEither] from an [IO] instance, invoking [IO] for each invocation of [IOEither]
func FromIO[E, A any](mr io.IO[A]) IOEither[E, A] { func FromIO[E, A any](mr IO[A]) IOEither[E, A] {
return RightIO[E](mr) return RightIO[E](mr)
} }
@@ -120,11 +123,11 @@ func FromLazy[E, A any](mr lazy.Lazy[A]) IOEither[E, A] {
} }
func MonadMap[E, A, B any](fa IOEither[E, A], f func(A) B) IOEither[E, B] { func MonadMap[E, A, B any](fa IOEither[E, A], f func(A) B) IOEither[E, B] {
return eithert.MonadMap(io.MonadMap[either.Either[E, A], either.Either[E, B]], fa, f) return eithert.MonadMap(io.MonadMap[Either[E, A], Either[E, B]], fa, f)
} }
func Map[E, A, B any](f func(A) B) Mapper[E, A, B] { func Map[E, A, B any](f func(A) B) Mapper[E, A, B] {
return eithert.Map(io.Map[either.Either[E, A], either.Either[E, B]], f) return eithert.Map(io.Map[Either[E, A], Either[E, B]], f)
} }
func MonadMapTo[E, A, B any](fa IOEither[E, A], b B) IOEither[E, B] { func MonadMapTo[E, A, B any](fa IOEither[E, A], b B) IOEither[E, B] {
@@ -136,14 +139,14 @@ func MapTo[E, A, B any](b B) Mapper[E, A, B] {
} }
func MonadChain[E, A, B any](fa IOEither[E, A], f func(A) IOEither[E, B]) IOEither[E, B] { func MonadChain[E, A, B any](fa IOEither[E, A], f func(A) IOEither[E, B]) IOEither[E, B] {
return eithert.MonadChain(io.MonadChain[either.Either[E, A], either.Either[E, B]], io.MonadOf[either.Either[E, B]], fa, f) return eithert.MonadChain(io.MonadChain[Either[E, A], Either[E, B]], io.MonadOf[Either[E, B]], fa, f)
} }
func Chain[E, A, B any](f func(A) IOEither[E, B]) Mapper[E, A, B] { func Chain[E, A, B any](f func(A) IOEither[E, B]) Mapper[E, A, B] {
return eithert.Chain(io.Chain[either.Either[E, A], either.Either[E, B]], io.Of[either.Either[E, B]], f) return eithert.Chain(io.Chain[Either[E, A], Either[E, B]], io.Of[Either[E, B]], f)
} }
func MonadChainEitherK[E, A, B any](ma IOEither[E, A], f func(A) either.Either[E, B]) IOEither[E, B] { func MonadChainEitherK[E, A, B any](ma IOEither[E, A], f func(A) Either[E, B]) IOEither[E, B] {
return fromeither.MonadChainEitherK( return fromeither.MonadChainEitherK(
MonadChain[E, A, B], MonadChain[E, A, B],
FromEither[E, B], FromEither[E, B],
@@ -152,7 +155,7 @@ func MonadChainEitherK[E, A, B any](ma IOEither[E, A], f func(A) either.Either[E
) )
} }
func ChainEitherK[E, A, B any](f func(A) either.Either[E, B]) func(IOEither[E, A]) IOEither[E, B] { func ChainEitherK[E, A, B any](f func(A) Either[E, B]) func(IOEither[E, A]) IOEither[E, B] {
return fromeither.ChainEitherK( return fromeither.ChainEitherK(
Chain[E, A, B], Chain[E, A, B],
FromEither[E, B], FromEither[E, B],
@@ -162,46 +165,46 @@ func ChainEitherK[E, A, B any](f func(A) either.Either[E, B]) func(IOEither[E, A
func MonadAp[B, E, A any](mab IOEither[E, func(A) B], ma IOEither[E, A]) IOEither[E, B] { func MonadAp[B, E, A any](mab IOEither[E, func(A) B], ma IOEither[E, A]) IOEither[E, B] {
return eithert.MonadAp( return eithert.MonadAp(
io.MonadAp[either.Either[E, A], either.Either[E, B]], io.MonadAp[Either[E, A], Either[E, B]],
io.MonadMap[either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]], io.MonadMap[Either[E, func(A) B], func(Either[E, A]) Either[E, B]],
mab, ma) mab, ma)
} }
// Ap is an alias of [ApPar] // Ap is an alias of [ApPar]
func Ap[B, E, A any](ma IOEither[E, A]) Mapper[E, func(A) B, B] { func Ap[B, E, A any](ma IOEither[E, A]) Mapper[E, func(A) B, B] {
return eithert.Ap( return eithert.Ap(
io.Ap[either.Either[E, B], either.Either[E, A]], io.Ap[Either[E, B], Either[E, A]],
io.Map[either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]], io.Map[Either[E, func(A) B], func(Either[E, A]) Either[E, B]],
ma) ma)
} }
func MonadApPar[B, E, A any](mab IOEither[E, func(A) B], ma IOEither[E, A]) IOEither[E, B] { func MonadApPar[B, E, A any](mab IOEither[E, func(A) B], ma IOEither[E, A]) IOEither[E, B] {
return eithert.MonadAp( return eithert.MonadAp(
io.MonadApPar[either.Either[E, A], either.Either[E, B]], io.MonadApPar[Either[E, A], Either[E, B]],
io.MonadMap[either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]], io.MonadMap[Either[E, func(A) B], func(Either[E, A]) Either[E, B]],
mab, ma) mab, ma)
} }
// ApPar applies function and value in parallel // ApPar applies function and value in parallel
func ApPar[B, E, A any](ma IOEither[E, A]) Mapper[E, func(A) B, B] { func ApPar[B, E, A any](ma IOEither[E, A]) Mapper[E, func(A) B, B] {
return eithert.Ap( return eithert.Ap(
io.ApPar[either.Either[E, B], either.Either[E, A]], io.ApPar[Either[E, B], Either[E, A]],
io.Map[either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]], io.Map[Either[E, func(A) B], func(Either[E, A]) Either[E, B]],
ma) ma)
} }
func MonadApSeq[B, E, A any](mab IOEither[E, func(A) B], ma IOEither[E, A]) IOEither[E, B] { func MonadApSeq[B, E, A any](mab IOEither[E, func(A) B], ma IOEither[E, A]) IOEither[E, B] {
return eithert.MonadAp( return eithert.MonadAp(
io.MonadApSeq[either.Either[E, A], either.Either[E, B]], io.MonadApSeq[Either[E, A], Either[E, B]],
io.MonadMap[either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]], io.MonadMap[Either[E, func(A) B], func(Either[E, A]) Either[E, B]],
mab, ma) mab, ma)
} }
// ApSeq applies function and value sequentially // ApSeq applies function and value sequentially
func ApSeq[B, E, A any](ma IOEither[E, A]) func(IOEither[E, func(A) B]) IOEither[E, B] { func ApSeq[B, E, A any](ma IOEither[E, A]) func(IOEither[E, func(A) B]) IOEither[E, B] {
return eithert.Ap( return eithert.Ap(
io.ApSeq[either.Either[E, B], either.Either[E, A]], io.ApSeq[Either[E, B], Either[E, A]],
io.Map[either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]], io.Map[Either[E, func(A) B], func(Either[E, A]) Either[E, B]],
ma) ma)
} }
@@ -210,14 +213,14 @@ func Flatten[E, A any](mma IOEither[E, IOEither[E, A]]) IOEither[E, A] {
} }
func TryCatch[E, A any](f func() (A, error), onThrow func(error) E) IOEither[E, A] { func TryCatch[E, A any](f func() (A, error), onThrow func(error) E) IOEither[E, A] {
return func() either.Either[E, A] { return func() Either[E, A] {
a, err := f() a, err := f()
return either.TryCatch(a, err, onThrow) return either.TryCatch(a, err, onThrow)
} }
} }
func TryCatchError[A any](f func() (A, error)) IOEither[error, A] { func TryCatchError[A any](f func() (A, error)) IOEither[error, A] {
return func() either.Either[error, A] { return func() Either[error, A] {
return either.TryCatchError(f()) return either.TryCatchError(f())
} }
} }
@@ -228,7 +231,7 @@ func Memoize[E, A any](ma IOEither[E, A]) IOEither[E, A] {
func MonadMapLeft[E1, E2, A any](fa IOEither[E1, A], f func(E1) E2) IOEither[E2, A] { func MonadMapLeft[E1, E2, A any](fa IOEither[E1, A], f func(E1) E2) IOEither[E2, A] {
return eithert.MonadMapLeft( return eithert.MonadMapLeft(
io.MonadMap[either.Either[E1, A], either.Either[E2, A]], io.MonadMap[Either[E1, A], Either[E2, A]],
fa, fa,
f, f,
) )
@@ -236,28 +239,28 @@ func MonadMapLeft[E1, E2, A any](fa IOEither[E1, A], f func(E1) E2) IOEither[E2,
func MapLeft[A, E1, E2 any](f func(E1) E2) func(IOEither[E1, A]) IOEither[E2, A] { func MapLeft[A, E1, E2 any](f func(E1) E2) func(IOEither[E1, A]) IOEither[E2, A] {
return eithert.MapLeft( return eithert.MapLeft(
io.Map[either.Either[E1, A], either.Either[E2, A]], io.Map[Either[E1, A], Either[E2, A]],
f, f,
) )
} }
func MonadBiMap[E1, E2, A, B any](fa IOEither[E1, A], f func(E1) E2, g func(A) B) IOEither[E2, B] { func MonadBiMap[E1, E2, A, B any](fa IOEither[E1, A], f func(E1) E2, g func(A) B) IOEither[E2, B] {
return eithert.MonadBiMap(io.MonadMap[either.Either[E1, A], either.Either[E2, B]], fa, f, g) return eithert.MonadBiMap(io.MonadMap[Either[E1, A], 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.
func BiMap[E1, E2, A, B any](f func(E1) E2, g func(A) B) func(IOEither[E1, A]) IOEither[E2, B] { func BiMap[E1, E2, A, B any](f func(E1) E2, g func(A) B) func(IOEither[E1, A]) IOEither[E2, B] {
return eithert.BiMap(io.Map[either.Either[E1, A], either.Either[E2, B]], f, g) return eithert.BiMap(io.Map[Either[E1, A], Either[E2, B]], f, g)
} }
// Fold converts an IOEither into an IO // Fold converts an IOEither into an IO
func Fold[E, A, B any](onLeft func(E) io.IO[B], onRight func(A) io.IO[B]) func(IOEither[E, A]) io.IO[B] { func Fold[E, A, B any](onLeft func(E) IO[B], onRight func(A) IO[B]) func(IOEither[E, A]) IO[B] {
return eithert.MatchE(io.MonadChain[either.Either[E, A], B], onLeft, onRight) return eithert.MatchE(io.MonadChain[Either[E, A], B], onLeft, onRight)
} }
// GetOrElse extracts the value or maps the error // GetOrElse extracts the value or maps the error
func GetOrElse[E, A any](onLeft func(E) io.IO[A]) func(IOEither[E, A]) io.IO[A] { func GetOrElse[E, A any](onLeft func(E) IO[A]) func(IOEither[E, A]) IO[A] {
return eithert.GetOrElse(io.MonadChain[either.Either[E, A], A], io.MonadOf[A], onLeft) return eithert.GetOrElse(io.MonadChain[Either[E, A], A], io.MonadOf[A], onLeft)
} }
// MonadChainTo composes to the second monad ignoring the return value of the first // MonadChainTo composes to the second monad ignoring the return value of the first
@@ -289,7 +292,7 @@ func ChainFirst[E, A, B any](f func(A) IOEither[E, B]) Mapper[E, A, A] {
) )
} }
func MonadChainFirstEitherK[A, E, B any](ma IOEither[E, A], f func(A) either.Either[E, B]) IOEither[E, A] { func MonadChainFirstEitherK[A, E, B any](ma IOEither[E, A], f func(A) Either[E, B]) IOEither[E, A] {
return fromeither.MonadChainFirstEitherK( return fromeither.MonadChainFirstEitherK(
MonadChain[E, A, A], MonadChain[E, A, A],
MonadMap[E, B, A], MonadMap[E, B, A],
@@ -299,7 +302,7 @@ func MonadChainFirstEitherK[A, E, B any](ma IOEither[E, A], f func(A) either.Eit
) )
} }
func ChainFirstEitherK[A, E, B any](f func(A) either.Either[E, B]) Mapper[E, A, A] { func ChainFirstEitherK[A, E, B any](f func(A) Either[E, B]) Mapper[E, A, A] {
return fromeither.ChainFirstEitherK( return fromeither.ChainFirstEitherK(
Chain[E, A, A], Chain[E, A, A],
Map[E, B, A], Map[E, B, A],
@@ -309,7 +312,7 @@ func ChainFirstEitherK[A, E, B any](f func(A) either.Either[E, B]) Mapper[E, A,
} }
// MonadChainFirstIOK runs [IO] the monad returned by the function but returns the result of the original monad // MonadChainFirstIOK runs [IO] the monad returned by the function but returns the result of the original monad
func MonadChainFirstIOK[E, A, B any](ma IOEither[E, A], f func(A) io.IO[B]) IOEither[E, A] { func MonadChainFirstIOK[E, A, B any](ma IOEither[E, A], f func(A) IO[B]) IOEither[E, A] {
return fromio.MonadChainFirstIOK( return fromio.MonadChainFirstIOK(
MonadChain[E, A, A], MonadChain[E, A, A],
MonadMap[E, B, A], MonadMap[E, B, A],
@@ -320,7 +323,7 @@ func MonadChainFirstIOK[E, A, B any](ma IOEither[E, A], f func(A) io.IO[B]) IOEi
} }
// ChainFirstIOK runs the [IO] monad returned by the function but returns the result of the original monad // ChainFirstIOK runs the [IO] monad returned by the function but returns the result of the original monad
func ChainFirstIOK[E, A, B any](f func(A) io.IO[B]) func(IOEither[E, A]) IOEither[E, A] { func ChainFirstIOK[E, A, B any](f func(A) IO[B]) func(IOEither[E, A]) IOEither[E, A] {
return fromio.ChainFirstIOK( return fromio.ChainFirstIOK(
Chain[E, A, A], Chain[E, A, A],
Map[E, B, A], Map[E, B, A],
@@ -329,16 +332,16 @@ func ChainFirstIOK[E, A, B any](f func(A) io.IO[B]) func(IOEither[E, A]) IOEithe
) )
} }
func MonadFold[E, A, B any](ma IOEither[E, A], onLeft func(E) io.IO[B], onRight func(A) io.IO[B]) io.IO[B] { func MonadFold[E, A, B any](ma IOEither[E, A], onLeft func(E) IO[B], onRight func(A) IO[B]) IO[B] {
return eithert.FoldE(io.MonadChain[either.Either[E, A], B], ma, onLeft, onRight) return eithert.FoldE(io.MonadChain[Either[E, A], B], ma, onLeft, onRight)
} }
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource // WithResource constructs a function that creates a resource, then operates on it and then releases the resource
func WithResource[A, E, R, ANY any](onCreate IOEither[E, R], onRelease func(R) IOEither[E, ANY]) func(func(R) IOEither[E, A]) IOEither[E, A] { func WithResource[A, E, R, ANY any](onCreate IOEither[E, R], onRelease func(R) IOEither[E, ANY]) func(func(R) IOEither[E, A]) IOEither[E, A] {
return file.WithResource( return file.WithResource(
MonadChain[E, R, A], MonadChain[E, R, A],
MonadFold[E, A, either.Either[E, A]], MonadFold[E, A, Either[E, A]],
MonadFold[E, ANY, either.Either[E, A]], MonadFold[E, ANY, Either[E, A]],
MonadMap[E, ANY, A], MonadMap[E, ANY, A],
Left[A, E], Left[A, E],
)(function.Constant(onCreate), onRelease) )(function.Constant(onCreate), onRelease)
@@ -366,8 +369,8 @@ func Defer[E, A any](gen lazy.Lazy[IOEither[E, A]]) IOEither[E, A] {
// MonadAlt identifies an associative operation on a type constructor // MonadAlt identifies an associative operation on a type constructor
func MonadAlt[E, A any](first IOEither[E, A], second lazy.Lazy[IOEither[E, A]]) IOEither[E, A] { func MonadAlt[E, A any](first IOEither[E, A], second lazy.Lazy[IOEither[E, A]]) IOEither[E, A] {
return eithert.MonadAlt( return eithert.MonadAlt(
io.Of[either.Either[E, A]], io.Of[Either[E, A]],
io.MonadChain[either.Either[E, A], either.Either[E, A]], io.MonadChain[Either[E, A], Either[E, A]],
first, first,
second, second,
@@ -397,10 +400,10 @@ func ToIOOption[E, A any](ioe IOEither[E, A]) IOO.IOOption[A] {
// Delay creates an operation that passes in the value after some delay // Delay creates an operation that passes in the value after some delay
func Delay[E, A any](delay time.Duration) Mapper[E, A, A] { func Delay[E, A any](delay time.Duration) Mapper[E, A, A] {
return io.Delay[either.Either[E, A]](delay) return io.Delay[Either[E, A]](delay)
} }
// After creates an operation that passes after the given [time.Time] // After creates an operation that passes after the given [time.Time]
func After[E, A any](timestamp time.Time) Mapper[E, A, A] { func After[E, A any](timestamp time.Time) Mapper[E, A, A] {
return io.After[either.Either[E, A]](timestamp) return io.After[Either[E, A]](timestamp)
} }

View File

@@ -16,7 +16,6 @@
package ioeither package ioeither
import ( import (
"github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/io" "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 +28,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(either.Either[E, A]) bool, check func(Either[E, A]) bool,
) IOEither[E, A] { ) IOEither[E, A] {
return io.Retrying(policy, action, check) return io.Retrying(policy, action, check)
} }

View File

@@ -18,11 +18,10 @@ package ioeither
import ( import (
"context" "context"
"github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/io" "github.com/IBM/fp-go/v2/io"
) )
// WithLock executes the provided IO operation in the scope of a lock // WithLock executes the provided IO operation in the scope of a lock
func WithLock[E, A any](lock io.IO[context.CancelFunc]) func(fa IOEither[E, A]) IOEither[E, A] { func WithLock[E, A any](lock IO[context.CancelFunc]) func(fa IOEither[E, A]) IOEither[E, A] {
return io.WithLock[either.Either[E, A]](lock) return io.WithLock[Either[E, A]](lock)
} }

View File

@@ -16,95 +16,169 @@
package ioeither package ioeither
import ( import (
G "github.com/IBM/fp-go/v2/ioeither/generic" "github.com/IBM/fp-go/v2/function"
"github.com/IBM/fp-go/v2/internal/array"
"github.com/IBM/fp-go/v2/internal/record"
) )
// TraverseArray transforms an array // TraverseArray transforms an array
func TraverseArray[E, A, B any](f func(A) IOEither[E, B]) func([]A) IOEither[E, []B] { func TraverseArray[E, A, B any](f func(A) IOEither[E, B]) func([]A) IOEither[E, []B] {
return G.TraverseArray[IOEither[E, B], IOEither[E, []B], []A](f) return array.Traverse[[]A](
Of[E, []B],
Map[E, []B, func(B) []B],
Ap[[]B, E, B],
f,
)
} }
// TraverseArrayWithIndex transforms an array // TraverseArrayWithIndex transforms an array
func TraverseArrayWithIndex[E, A, B any](f func(int, A) IOEither[E, B]) func([]A) IOEither[E, []B] { func TraverseArrayWithIndex[E, A, B any](f func(int, A) IOEither[E, B]) func([]A) IOEither[E, []B] {
return G.TraverseArrayWithIndex[IOEither[E, B], IOEither[E, []B], []A](f) return array.TraverseWithIndex[[]A](
Of[E, []B],
Map[E, []B, func(B) []B],
Ap[[]B, E, B],
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[E, A any](ma []IOEither[E, A]) IOEither[E, []A] { func SequenceArray[E, A any](ma []IOEither[E, A]) IOEither[E, []A] {
return G.SequenceArray[IOEither[E, A], IOEither[E, []A]](ma) return TraverseArray(function.Identity[IOEither[E, A]])(ma)
} }
// TraverseRecord transforms a record // TraverseRecord transforms a record
func TraverseRecord[K comparable, E, A, B any](f func(A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] { func TraverseRecord[K comparable, E, A, B any](f func(A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] {
return G.TraverseRecord[IOEither[E, B], IOEither[E, map[K]B], map[K]A](f) return record.Traverse[map[K]A](
Of[E, map[K]B],
Map[E, map[K]B, func(B) map[K]B],
Ap[map[K]B, E, B],
f,
)
} }
// TraverseRecordWithIndex transforms a record // TraverseRecordWithIndex transforms a record
func TraverseRecordWithIndex[K comparable, E, A, B any](f func(K, A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] { func TraverseRecordWithIndex[K comparable, E, A, B any](f func(K, A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] {
return G.TraverseRecordWithIndex[IOEither[E, B], IOEither[E, map[K]B], map[K]A](f) return record.TraverseWithIndex[map[K]A](
Of[E, map[K]B],
Map[E, map[K]B, func(B) map[K]B],
Ap[map[K]B, E, B],
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[K comparable, E, A any](ma map[K]IOEither[E, A]) IOEither[E, map[K]A] { func SequenceRecord[K comparable, E, A any](ma map[K]IOEither[E, A]) IOEither[E, map[K]A] {
return G.SequenceRecord[IOEither[E, A], IOEither[E, map[K]A]](ma) return TraverseRecord[K](function.Identity[IOEither[E, A]])(ma)
} }
// TraverseArraySeq transforms an array // TraverseArraySeq transforms an array
func TraverseArraySeq[E, A, B any](f func(A) IOEither[E, B]) func([]A) IOEither[E, []B] { func TraverseArraySeq[E, A, B any](f func(A) IOEither[E, B]) func([]A) IOEither[E, []B] {
return G.TraverseArraySeq[IOEither[E, B], IOEither[E, []B], []A](f) return array.Traverse[[]A](
Of[E, []B],
Map[E, []B, func(B) []B],
ApSeq[[]B, E, B],
f,
)
} }
// TraverseArrayWithIndexSeq transforms an array // TraverseArrayWithIndexSeq transforms an array
func TraverseArrayWithIndexSeq[E, A, B any](f func(int, A) IOEither[E, B]) func([]A) IOEither[E, []B] { func TraverseArrayWithIndexSeq[E, A, B any](f func(int, A) IOEither[E, B]) func([]A) IOEither[E, []B] {
return G.TraverseArrayWithIndexSeq[IOEither[E, B], IOEither[E, []B], []A](f) return array.TraverseWithIndex[[]A](
Of[E, []B],
Map[E, []B, func(B) []B],
ApSeq[[]B, E, B],
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[E, A any](ma []IOEither[E, A]) IOEither[E, []A] { func SequenceArraySeq[E, A any](ma []IOEither[E, A]) IOEither[E, []A] {
return G.SequenceArraySeq[IOEither[E, A], IOEither[E, []A]](ma) return TraverseArraySeq(function.Identity[IOEither[E, A]])(ma)
} }
// TraverseRecordSeq transforms a record // TraverseRecordSeq transforms a record
func TraverseRecordSeq[K comparable, E, A, B any](f func(A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] { func TraverseRecordSeq[K comparable, E, A, B any](f func(A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] {
return G.TraverseRecordSeq[IOEither[E, B], IOEither[E, map[K]B], map[K]A](f) return record.Traverse[map[K]A](
Of[E, map[K]B],
Map[E, map[K]B, func(B) map[K]B],
ApSeq[map[K]B, E, B],
f,
)
} }
// TraverseRecordWithIndexSeq transforms a record // TraverseRecordWithIndexSeq transforms a record
func TraverseRecordWithIndexSeq[K comparable, E, A, B any](f func(K, A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] { func TraverseRecordWithIndexSeq[K comparable, E, A, B any](f func(K, A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] {
return G.TraverseRecordWithIndexSeq[IOEither[E, B], IOEither[E, map[K]B], map[K]A](f) return record.TraverseWithIndex[map[K]A](
Of[E, map[K]B],
Map[E, map[K]B, func(B) map[K]B],
ApSeq[map[K]B, E, B],
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[K comparable, E, A any](ma map[K]IOEither[E, A]) IOEither[E, map[K]A] { func SequenceRecordSeq[K comparable, E, A any](ma map[K]IOEither[E, A]) IOEither[E, map[K]A] {
return G.SequenceRecordSeq[IOEither[E, A], IOEither[E, map[K]A]](ma) return TraverseRecordSeq[K](function.Identity[IOEither[E, A]])(ma)
} }
// TraverseArrayPar transforms an array // TraverseArrayPar transforms an array
func TraverseArrayPar[E, A, B any](f func(A) IOEither[E, B]) func([]A) IOEither[E, []B] { func TraverseArrayPar[E, A, B any](f func(A) IOEither[E, B]) func([]A) IOEither[E, []B] {
return G.TraverseArrayPar[IOEither[E, B], IOEither[E, []B], []A](f) return array.Traverse[[]A](
Of[E, []B],
Map[E, []B, func(B) []B],
ApPar[[]B, E, B],
f,
)
} }
// TraverseArrayWithIndexPar transforms an array // TraverseArrayWithIndexPar transforms an array
func TraverseArrayWithIndexPar[E, A, B any](f func(int, A) IOEither[E, B]) func([]A) IOEither[E, []B] { func TraverseArrayWithIndexPar[E, A, B any](f func(int, A) IOEither[E, B]) func([]A) IOEither[E, []B] {
return G.TraverseArrayWithIndexPar[IOEither[E, B], IOEither[E, []B], []A](f) return array.TraverseWithIndex[[]A](
Of[E, []B],
Map[E, []B, func(B) []B],
ApPar[[]B, E, B],
f,
)
} }
// SequenceArrayPar converts a homogeneous Paruence of either into an either of Paruence // SequenceArrayPar converts a homogeneous Paruence of either into an either of Paruence
func SequenceArrayPar[E, A any](ma []IOEither[E, A]) IOEither[E, []A] { func SequenceArrayPar[E, A any](ma []IOEither[E, A]) IOEither[E, []A] {
return G.SequenceArrayPar[IOEither[E, A], IOEither[E, []A]](ma) return TraverseArrayPar(function.Identity[IOEither[E, A]])(ma)
} }
// TraverseRecordPar transforms a record // TraverseRecordPar transforms a record
func TraverseRecordPar[K comparable, E, A, B any](f func(A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] { func TraverseRecordPar[K comparable, E, A, B any](f func(A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] {
return G.TraverseRecordPar[IOEither[E, B], IOEither[E, map[K]B], map[K]A](f) return record.Traverse[map[K]A](
Of[E, map[K]B],
Map[E, map[K]B, func(B) map[K]B],
ApPar[map[K]B, E, B],
f,
)
} }
// TraverseRecordWithIndexPar transforms a record // TraverseRecordWithIndexPar transforms a record
func TraverseRecordWithIndexPar[K comparable, E, A, B any](f func(K, A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] { func TraverseRecordWithIndexPar[K comparable, E, A, B any](f func(K, A) IOEither[E, B]) func(map[K]A) IOEither[E, map[K]B] {
return G.TraverseRecordWithIndexPar[IOEither[E, B], IOEither[E, map[K]B], map[K]A](f) return record.TraverseWithIndex[map[K]A](
Of[E, map[K]B],
Map[E, map[K]B, func(B) map[K]B],
ApSeq[map[K]B, E, B],
f,
)
} }
// SequenceRecordPar converts a homogeneous Paruence of either into an either of Paruence // SequenceRecordPar converts a homogeneous Paruence of either into an either of Paruence
func SequenceRecordPar[K comparable, E, A any](ma map[K]IOEither[E, A]) IOEither[E, map[K]A] { func SequenceRecordPar[K comparable, E, A any](ma map[K]IOEither[E, A]) IOEither[E, map[K]A] {
return G.SequenceRecordPar[IOEither[E, A], IOEither[E, map[K]A]](ma) return TraverseRecordPar[K](function.Identity[IOEither[E, A]])(ma)
} }

View File

@@ -16,14 +16,14 @@
package lazy package lazy
import ( import (
G "github.com/IBM/fp-go/v2/io/generic" "github.com/IBM/fp-go/v2/io"
) )
// 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[S any]( func Do[S any](
empty S, empty S,
) Lazy[S] { ) Lazy[S] {
return G.Do[Lazy[S], S](empty) return io.Do(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]
@@ -31,7 +31,7 @@ func Bind[S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
f func(S1) Lazy[T], f func(S1) Lazy[T],
) func(Lazy[S1]) Lazy[S2] { ) func(Lazy[S1]) Lazy[S2] {
return G.Bind[Lazy[S1], Lazy[S2], Lazy[T], S1, S2, T](setter, f) return io.Bind(setter, f)
} }
// 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]
@@ -39,7 +39,7 @@ func Let[S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
f func(S1) T, f func(S1) T,
) func(Lazy[S1]) Lazy[S2] { ) func(Lazy[S1]) Lazy[S2] {
return G.Let[Lazy[S1], Lazy[S2], S1, S2, T](setter, f) return io.Let(setter, f)
} }
// 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]
@@ -47,14 +47,14 @@ func LetTo[S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
b T, b T,
) func(Lazy[S1]) Lazy[S2] { ) func(Lazy[S1]) Lazy[S2] {
return G.LetTo[Lazy[S1], Lazy[S2], S1, S2, T](setter, b) return io.LetTo(setter, b)
} }
// BindTo initializes a new state [S1] from a value [T] // BindTo initializes a new state [S1] from a value [T]
func BindTo[S1, T any]( func BindTo[S1, T any](
setter func(T) S1, setter func(T) S1,
) func(Lazy[T]) Lazy[S1] { ) func(Lazy[T]) Lazy[S1] {
return G.BindTo[Lazy[S1], Lazy[T], S1, T](setter) return io.BindTo(setter)
} }
// 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
@@ -62,5 +62,5 @@ func ApS[S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
fa Lazy[T], fa Lazy[T],
) func(Lazy[S1]) Lazy[S2] { ) func(Lazy[S1]) Lazy[S2] {
return G.ApS[Lazy[S1], Lazy[S2], Lazy[T], S1, S2, T](setter, fa) return io.ApS(setter, fa)
} }

View File

@@ -21,7 +21,7 @@ import (
G "github.com/IBM/fp-go/v2/readerio/generic" G "github.com/IBM/fp-go/v2/readerio/generic"
) )
type ReaderIO[E, A any] R.Reader[E, IO.IO[A]] type ReaderIO[E, A any] = R.Reader[E, IO.IO[A]]
// FromIO converts an [IO.IO] to a [ReaderIO] // FromIO converts an [IO.IO] to a [ReaderIO]
func FromIO[E, A any](t IO.IO[A]) ReaderIO[E, A] { func FromIO[E, A any](t IO.IO[A]) ReaderIO[E, A] {

View File

@@ -21,7 +21,7 @@ import (
"testing" "testing"
A "github.com/IBM/fp-go/v2/array" A "github.com/IBM/fp-go/v2/array"
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"
TST "github.com/IBM/fp-go/v2/internal/testing" TST "github.com/IBM/fp-go/v2/internal/testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -35,9 +35,9 @@ func TestTraverseArray(t *testing.T) {
return Left[context.Context, string, string]("e") return Left[context.Context, string, string]("e")
}) })
ctx := context.Background() ctx := context.Background()
assert.Equal(t, ET.Right[string](A.Empty[string]()), F.Pipe1(A.Empty[string](), f)(ctx)()) assert.Equal(t, either.Right[string](A.Empty[string]()), F.Pipe1(A.Empty[string](), f)(ctx)())
assert.Equal(t, ET.Right[string]([]string{"aa", "bb"}), F.Pipe1([]string{"a", "b"}, f)(ctx)()) assert.Equal(t, either.Right[string]([]string{"aa", "bb"}), F.Pipe1([]string{"a", "b"}, f)(ctx)())
assert.Equal(t, ET.Left[[]string]("e"), F.Pipe1([]string{"a", ""}, f)(ctx)()) assert.Equal(t, either.Left[[]string]("e"), F.Pipe1([]string{"a", ""}, f)(ctx)())
} }
func TestSequenceArray(t *testing.T) { func TestSequenceArray(t *testing.T) {

View File

@@ -16,7 +16,7 @@
package readerioeither package readerioeither
import ( import (
ET "github.com/IBM/fp-go/v2/either" "github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/readerioeither/generic" G "github.com/IBM/fp-go/v2/readerioeither/generic"
) )
@@ -27,7 +27,7 @@ func Bracket[
acquire ReaderIOEither[R, E, A], acquire ReaderIOEither[R, E, A],
use func(A) ReaderIOEither[R, E, B], use func(A) ReaderIOEither[R, E, B],
release func(A, ET.Either[E, B]) ReaderIOEither[R, E, ANY], release func(A, either.Either[E, B]) ReaderIOEither[R, E, ANY],
) ReaderIOEither[R, E, B] { ) ReaderIOEither[R, E, B] {
return G.Bracket(acquire, use, release) return G.Bracket(acquire, use, release)
} }

View File

@@ -16,13 +16,13 @@
package readerioeither package readerioeither
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"
G "github.com/IBM/fp-go/v2/readerioeither/generic" G "github.com/IBM/fp-go/v2/readerioeither/generic"
) )
// 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[R, E, A any](eq EQ.Eq[ET.Either[E, A]]) func(R) EQ.Eq[ReaderIOEither[R, E, A]] { func Eq[R, E, A any](eq EQ.Eq[either.Either[E, A]]) func(R) EQ.Eq[ReaderIOEither[R, E, A]] {
return G.Eq[ReaderIOEither[R, E, A]](eq) return G.Eq[ReaderIOEither[R, E, A]](eq)
} }

View File

@@ -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[GRS ~func(R) GS, GS ~func() ET.Either[E, S], R, E, S any]( func Do[GRS ~func(R) GS, GS ~func() either.Either[E, S], R, E, S any](
empty S, empty S,
) GRS { ) GRS {
return Of[GRS, GS, R, E, S](empty) return Of[GRS, GS, R, 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[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GRT ~func(R) GT, GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], GT ~func() ET.Either[E, T], R, E, S1, S2, T any]( func Bind[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GRT ~func(R) GT, GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], GT ~func() either.Either[E, T], R, E, S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
f func(S1) GRT, f func(S1) GRT,
) func(GRS1) GRS2 { ) func(GRS1) GRS2 {
@@ -43,7 +43,7 @@ func Bind[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GRT ~func(R) GT, GS1 ~func() ET.
} }
// 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[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], R, E, S1, S2, T any]( func Let[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], R, 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(GRS1) GRS2 { ) func(GRS1) GRS2 {
@@ -55,7 +55,7 @@ func Let[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GS1 ~func() ET.Either[E, S1], GS2
} }
// 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[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], R, E, S1, S2, B any]( func LetTo[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], R, E, S1, S2, B any](
key func(B) func(S1) S2, key func(B) func(S1) S2,
b B, b B,
) func(GRS1) GRS2 { ) func(GRS1) GRS2 {
@@ -67,7 +67,7 @@ func LetTo[GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GS1 ~func() ET.Either[E, S1], G
} }
// BindTo initializes a new state [S1] from a value [T] // BindTo initializes a new state [S1] from a value [T]
func BindTo[GRS1 ~func(R) GS1, GRT ~func(R) GT, GS1 ~func() ET.Either[E, S1], GT ~func() ET.Either[E, T], R, E, S1, T any]( func BindTo[GRS1 ~func(R) GS1, GRT ~func(R) GT, GS1 ~func() either.Either[E, S1], GT ~func() either.Either[E, T], R, E, S1, T any](
setter func(T) S1, setter func(T) S1,
) func(GRT) GRS1 { ) func(GRT) GRS1 {
return C.BindTo( return C.BindTo(
@@ -77,7 +77,7 @@ func BindTo[GRS1 ~func(R) GS1, GRT ~func(R) GT, GS1 ~func() ET.Either[E, S1], GT
} }
// 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[GRTS1 ~func(R) GTS1, GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GRT ~func(R) GT, GTS1 ~func() ET.Either[E, func(T) S2], GS1 ~func() ET.Either[E, S1], GS2 ~func() ET.Either[E, S2], GT ~func() ET.Either[E, T], R, E, S1, S2, T any]( func ApS[GRTS1 ~func(R) GTS1, GRS1 ~func(R) GS1, GRS2 ~func(R) GS2, GRT ~func(R) GT, GTS1 ~func() either.Either[E, func(T) S2], GS1 ~func() either.Either[E, S1], GS2 ~func() either.Either[E, S2], GT ~func() either.Either[E, T], R, E, S1, S2, T any](
setter func(T) func(S1) S2, setter func(T) func(S1) S2,
fa GRT, fa GRT,
) func(GRS1) GRS2 { ) func(GRS1) GRS2 {

View File

@@ -16,7 +16,7 @@
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/bracket" G "github.com/IBM/fp-go/v2/internal/bracket"
I "github.com/IBM/fp-go/v2/readerio/generic" I "github.com/IBM/fp-go/v2/readerio/generic"
) )
@@ -28,20 +28,20 @@ func Bracket[
GB ~func(R) TB, GB ~func(R) TB,
GANY ~func(R) TANY, GANY ~func(R) TANY,
TA ~func() ET.Either[E, A], TA ~func() either.Either[E, A],
TB ~func() ET.Either[E, B], TB ~func() either.Either[E, B],
TANY ~func() ET.Either[E, ANY], TANY ~func() either.Either[E, ANY],
R, E, A, B, ANY any]( R, E, A, B, ANY any](
acquire GA, acquire GA,
use func(A) GB, use func(A) GB,
release func(A, ET.Either[E, B]) GANY, release func(A, either.Either[E, B]) GANY,
) GB { ) GB {
return G.Bracket[GA, GB, GANY, ET.Either[E, B], A, B]( return G.Bracket[GA, GB, GANY, either.Either[E, B], A, B](
I.Of[GB, TB, R, ET.Either[E, B]], I.Of[GB, TB, R, either.Either[E, B]],
MonadChain[GA, GB, TA, TB, R, E, A, B], MonadChain[GA, GB, TA, TB, R, E, A, B],
I.MonadChain[GB, GB, TB, TB, R, ET.Either[E, B], ET.Either[E, B]], I.MonadChain[GB, GB, TB, TB, R, either.Either[E, B], either.Either[E, B]],
MonadChain[GANY, GB, TANY, TB, R, E, ANY, B], MonadChain[GANY, GB, TANY, TB, R, E, ANY, B],
acquire, acquire,

View File

@@ -16,17 +16,17 @@
package generic package generic
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"
G "github.com/IBM/fp-go/v2/readerio/generic" G "github.com/IBM/fp-go/v2/readerio/generic"
) )
// 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[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](eq EQ.Eq[ET.Either[E, A]]) func(R) EQ.Eq[GEA] { func Eq[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](eq EQ.Eq[either.Either[E, A]]) func(R) EQ.Eq[GEA] {
return G.Eq[GEA](eq) return G.Eq[GEA](eq)
} }
// FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function // FromStrictEquals constructs an [EQ.Eq] from the canonical comparison function
func FromStrictEquals[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R any, E, A comparable]() func(R) EQ.Eq[GEA] { func FromStrictEquals[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R any, E, A comparable]() func(R) EQ.Eq[GEA] {
return Eq[GEA](ET.FromStrictEquals[E, A]()) return Eq[GEA](either.FromStrictEquals[E, A]())
} }

View File

@@ -5,13 +5,13 @@ package generic
import ( import (
E "github.com/IBM/fp-go/v2/either" E "github.com/IBM/fp-go/v2/either"
RD "github.com/IBM/fp-go/v2/reader/generic" reader "github.com/IBM/fp-go/v2/reader/generic"
) )
// From0 converts a function with 1 parameters returning a tuple into a function with 0 parameters returning a [GRA] // From0 converts a function with 1 parameters returning a tuple into a function with 0 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From0[GRA ~func(C) GIOA, F ~func(C) func() (R, error), GIOA ~func() E.Either[error, R], C, R any](f F) func() GRA { func From0[GRA ~func(C) GIOA, F ~func(C) func() (R, error), GIOA ~func() E.Either[error, R], C, R any](f F) func() GRA {
return RD.From0[GRA](func(r C) GIOA { return reader.From0[GRA](func(r C) GIOA {
return E.Eitherize0(f(r)) return E.Eitherize0(f(r))
}) })
} }
@@ -37,7 +37,7 @@ func Uneitherize0[GRA ~func(C) GIOA, F ~func(C) (R, error), GIOA ~func() E.Eithe
// From1 converts a function with 2 parameters returning a tuple into a function with 1 parameters returning a [GRA] // From1 converts a function with 2 parameters returning a tuple into a function with 1 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From1[GRA ~func(C) GIOA, F ~func(C, T0) func() (R, error), GIOA ~func() E.Either[error, R], T0, C, R any](f F) func(T0) GRA { func From1[GRA ~func(C) GIOA, F ~func(C, T0) func() (R, error), GIOA ~func() E.Either[error, R], T0, C, R any](f F) func(T0) GRA {
return RD.From1[GRA](func(r C, t0 T0) GIOA { return reader.From1[GRA](func(r C, t0 T0) GIOA {
return E.Eitherize0(f(r, t0)) return E.Eitherize0(f(r, t0))
}) })
} }
@@ -63,7 +63,7 @@ func Uneitherize1[GRA ~func(C) GIOA, F ~func(C, T0) (R, error), GIOA ~func() E.E
// From2 converts a function with 3 parameters returning a tuple into a function with 2 parameters returning a [GRA] // From2 converts a function with 3 parameters returning a tuple into a function with 2 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From2[GRA ~func(C) GIOA, F ~func(C, T0, T1) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, C, R any](f F) func(T0, T1) GRA { func From2[GRA ~func(C) GIOA, F ~func(C, T0, T1) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, C, R any](f F) func(T0, T1) GRA {
return RD.From2[GRA](func(r C, t0 T0, t1 T1) GIOA { return reader.From2[GRA](func(r C, t0 T0, t1 T1) GIOA {
return E.Eitherize0(f(r, t0, t1)) return E.Eitherize0(f(r, t0, t1))
}) })
} }
@@ -89,7 +89,7 @@ func Uneitherize2[GRA ~func(C) GIOA, F ~func(C, T0, T1) (R, error), GIOA ~func()
// From3 converts a function with 4 parameters returning a tuple into a function with 3 parameters returning a [GRA] // From3 converts a function with 4 parameters returning a tuple into a function with 3 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From3[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, C, R any](f F) func(T0, T1, T2) GRA { func From3[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, C, R any](f F) func(T0, T1, T2) GRA {
return RD.From3[GRA](func(r C, t0 T0, t1 T1, t2 T2) GIOA { return reader.From3[GRA](func(r C, t0 T0, t1 T1, t2 T2) GIOA {
return E.Eitherize0(f(r, t0, t1, t2)) return E.Eitherize0(f(r, t0, t1, t2))
}) })
} }
@@ -115,7 +115,7 @@ func Uneitherize3[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2) (R, error), GIOA ~fu
// From4 converts a function with 5 parameters returning a tuple into a function with 4 parameters returning a [GRA] // From4 converts a function with 5 parameters returning a tuple into a function with 4 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From4[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) GRA { func From4[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) GRA {
return RD.From4[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3) GIOA { return reader.From4[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3) GIOA {
return E.Eitherize0(f(r, t0, t1, t2, t3)) return E.Eitherize0(f(r, t0, t1, t2, t3))
}) })
} }
@@ -141,7 +141,7 @@ func Uneitherize4[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3) (R, error), GIOA
// From5 converts a function with 6 parameters returning a tuple into a function with 5 parameters returning a [GRA] // From5 converts a function with 6 parameters returning a tuple into a function with 5 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From5[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, C, R any](f F) func(T0, T1, T2, T3, T4) GRA { func From5[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, C, R any](f F) func(T0, T1, T2, T3, T4) GRA {
return RD.From5[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) GIOA { return reader.From5[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) GIOA {
return E.Eitherize0(f(r, t0, t1, t2, t3, t4)) return E.Eitherize0(f(r, t0, t1, t2, t3, t4))
}) })
} }
@@ -167,7 +167,7 @@ func Uneitherize5[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4) (R, error),
// From6 converts a function with 7 parameters returning a tuple into a function with 6 parameters returning a [GRA] // From6 converts a function with 7 parameters returning a tuple into a function with 6 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From6[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, C, R any](f F) func(T0, T1, T2, T3, T4, T5) GRA { func From6[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, C, R any](f F) func(T0, T1, T2, T3, T4, T5) GRA {
return RD.From6[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) GIOA { return reader.From6[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) GIOA {
return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5)) return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5))
}) })
} }
@@ -193,7 +193,7 @@ func Uneitherize6[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5) (R, erro
// From7 converts a function with 8 parameters returning a tuple into a function with 7 parameters returning a [GRA] // From7 converts a function with 8 parameters returning a tuple into a function with 7 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From7[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) GRA { func From7[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) GRA {
return RD.From7[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) GIOA { return reader.From7[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) GIOA {
return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6)) return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6))
}) })
} }
@@ -219,7 +219,7 @@ func Uneitherize7[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6) (R,
// From8 converts a function with 9 parameters returning a tuple into a function with 8 parameters returning a [GRA] // From8 converts a function with 9 parameters returning a tuple into a function with 8 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From8[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) GRA { func From8[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) GRA {
return RD.From8[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) GIOA { return reader.From8[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) GIOA {
return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7)) return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7))
}) })
} }
@@ -245,7 +245,7 @@ func Uneitherize8[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7)
// From9 converts a function with 10 parameters returning a tuple into a function with 9 parameters returning a [GRA] // From9 converts a function with 10 parameters returning a tuple into a function with 9 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From9[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) GRA { func From9[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) GRA {
return RD.From9[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) GIOA { return reader.From9[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) GIOA {
return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8)) return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8))
}) })
} }
@@ -271,7 +271,7 @@ func Uneitherize9[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7,
// From10 converts a function with 11 parameters returning a tuple into a function with 10 parameters returning a [GRA] // From10 converts a function with 11 parameters returning a tuple into a function with 10 parameters returning a [GRA]
// The first parameter is considerd to be the context [C]. // The first parameter is considerd to be the context [C].
func From10[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) GRA { func From10[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) func() (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) GRA {
return RD.From10[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) GIOA { return reader.From10[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) GIOA {
return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)) return E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
}) })
} }

View File

@@ -16,17 +16,17 @@
package generic package generic
import ( import (
ET "github.com/IBM/fp-go/v2/either" "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/internal/functor" "github.com/IBM/fp-go/v2/internal/functor"
"github.com/IBM/fp-go/v2/internal/monad" "github.com/IBM/fp-go/v2/internal/monad"
"github.com/IBM/fp-go/v2/internal/pointed" "github.com/IBM/fp-go/v2/internal/pointed"
) )
type readerIOEitherPointed[R, E, A any, GRA ~func(R) GIOA, GIOA ~func() ET.Either[E, A]] struct{} type readerIOEitherPointed[R, E, A any, GRA ~func(R) GIOA, GIOA ~func() either.Either[E, A]] struct{}
type readerIOEitherMonad[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GRAB ~func(R) GIOAB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], GIOAB ~func() ET.Either[E, func(A) B]] struct{} type readerIOEitherMonad[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GRAB ~func(R) GIOAB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], GIOAB ~func() either.Either[E, func(A) B]] struct{}
type readerIOEitherFunctor[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B]] struct{} type readerIOEitherFunctor[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B]] struct{}
func (o *readerIOEitherPointed[R, E, A, GRA, GIOA]) Of(a A) GRA { func (o *readerIOEitherPointed[R, E, A, GRA, GIOA]) Of(a A) GRA {
return Of[GRA, GIOA, R, E, A](a) return Of[GRA, GIOA, R, E, A](a)
@@ -53,16 +53,16 @@ func (o *readerIOEitherFunctor[R, E, A, B, GRA, GRB, GIOA, GIOB]) Map(f func(A)
} }
// Pointed implements the pointed operations for [ReaderIOEither] // Pointed implements the pointed operations for [ReaderIOEither]
func Pointed[R, E, A any, GRA ~func(R) GIOA, GIOA ~func() ET.Either[E, A]]() pointed.Pointed[A, GRA] { func Pointed[R, E, A any, GRA ~func(R) GIOA, GIOA ~func() either.Either[E, A]]() pointed.Pointed[A, GRA] {
return &readerIOEitherPointed[R, E, A, GRA, GIOA]{} return &readerIOEitherPointed[R, E, A, GRA, GIOA]{}
} }
// Functor implements the monadic operations for [ReaderIOEither] // Functor implements the monadic operations for [ReaderIOEither]
func Functor[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B]]() functor.Functor[A, B, GRA, GRB] { func Functor[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B]]() functor.Functor[A, B, GRA, GRB] {
return &readerIOEitherFunctor[R, E, A, B, GRA, GRB, GIOA, GIOB]{} return &readerIOEitherFunctor[R, E, A, B, GRA, GRB, GIOA, GIOB]{}
} }
// Monad implements the monadic operations for [ReaderIOEither] // Monad implements the monadic operations for [ReaderIOEither]
func Monad[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GRAB ~func(R) GIOAB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], GIOAB ~func() ET.Either[E, func(A) B]]() monad.Monad[A, B, GRA, GRB, GRAB] { func Monad[R, E, A, B any, GRA ~func(R) GIOA, GRB ~func(R) GIOB, GRAB ~func(R) GIOAB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], GIOAB ~func() either.Either[E, func(A) B]]() monad.Monad[A, B, GRA, GRB, GRAB] {
return &readerIOEitherMonad[R, E, A, B, GRA, GRB, GRAB, GIOA, GIOB, GIOAB]{} return &readerIOEitherMonad[R, E, A, B, GRA, GRB, GRAB, GIOA, GIOB, GIOAB]{}
} }

View File

@@ -16,7 +16,7 @@
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"
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,11 +32,11 @@ import (
) )
// MakeReader constructs an instance of a reader // MakeReader constructs an instance of a reader
func MakeReader[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](f func(R) GIOA) GEA { func MakeReader[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](f func(R) GIOA) GEA {
return f return f
} }
func MonadAlt[LAZY ~func() GEA, GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](first GEA, second LAZY) GEA { func MonadAlt[LAZY ~func() GEA, GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](first GEA, second LAZY) GEA {
return eithert.MonadAlt( return eithert.MonadAlt(
G.Of[GEA], G.Of[GEA],
G.MonadChain[GEA, GEA], G.MonadChain[GEA, GEA],
@@ -46,39 +46,39 @@ func MonadAlt[LAZY ~func() GEA, GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A],
) )
} }
func Alt[LAZY ~func() GEA, GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](second LAZY) func(GEA) GEA { func Alt[LAZY ~func() GEA, GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](second LAZY) func(GEA) GEA {
return F.Bind2nd(MonadAlt[LAZY], second) return F.Bind2nd(MonadAlt[LAZY], second)
} }
func MonadMap[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](fa GEA, f func(A) B) GEB { func MonadMap[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](fa GEA, f func(A) B) GEB {
return eithert.MonadMap(G.MonadMap[GEA, GEB, GIOA, GIOB, R, ET.Either[E, A], ET.Either[E, B]], fa, f) return eithert.MonadMap(G.MonadMap[GEA, GEB, GIOA, GIOB, R, either.Either[E, A], either.Either[E, B]], fa, f)
} }
func Map[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](f func(A) B) func(GEA) GEB { func Map[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](f func(A) B) func(GEA) GEB {
return F.Bind2nd(MonadMap[GEA, GEB, GIOA, GIOB, R, E, A, B], f) return F.Bind2nd(MonadMap[GEA, GEB, GIOA, GIOB, R, E, A, B], f)
} }
func MonadMapTo[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](fa GEA, b B) GEB { func MonadMapTo[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](fa GEA, b B) GEB {
return MonadMap[GEA, GEB](fa, F.Constant1[A](b)) return MonadMap[GEA, GEB](fa, F.Constant1[A](b))
} }
func MapTo[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](b B) func(GEA) GEB { func MapTo[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](b B) func(GEA) GEB {
return Map[GEA, GEB](F.Constant1[A](b)) return Map[GEA, GEB](F.Constant1[A](b))
} }
func MonadChain[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](fa GEA, f func(A) GEB) GEB { func MonadChain[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](fa GEA, f func(A) GEB) GEB {
return eithert.MonadChain( return eithert.MonadChain(
G.MonadChain[GEA, GEB, GIOA, GIOB, R, ET.Either[E, A], ET.Either[E, B]], G.MonadChain[GEA, GEB, GIOA, GIOB, R, either.Either[E, A], either.Either[E, B]],
G.Of[GEB, GIOB, R, ET.Either[E, B]], G.Of[GEB, GIOB, R, either.Either[E, B]],
fa, fa,
f) f)
} }
func Chain[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](f func(A) GEB) func(fa GEA) GEB { func Chain[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](f func(A) GEB) func(fa GEA) GEB {
return F.Bind2nd(MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], f) return F.Bind2nd(MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], f)
} }
func MonadChainFirst[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](fa GEA, f func(A) GEB) GEA { func MonadChainFirst[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](fa GEA, f func(A) GEB) GEA {
return C.MonadChainFirst( return C.MonadChainFirst(
MonadChain[GEA, GEA, GIOA, GIOA, R, E, A, A], MonadChain[GEA, GEA, GIOA, GIOA, R, E, A, A],
MonadMap[GEB, GEA, GIOB, GIOA, R, E, B, A], MonadMap[GEB, GEA, GIOB, GIOA, R, E, B, A],
@@ -86,11 +86,11 @@ func MonadChainFirst[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Eithe
f) f)
} }
func ChainFirst[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](f func(A) GEB) func(fa GEA) GEA { func ChainFirst[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](f func(A) GEB) func(fa GEA) GEA {
return F.Bind2nd(MonadChainFirst[GEA, GEB, GIOA, GIOB, R, E, A, B], f) return F.Bind2nd(MonadChainFirst[GEA, GEB, GIOA, GIOB, R, E, A, B], f)
} }
func MonadChainEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](ma GEA, f func(A) ET.Either[E, B]) GEB { func MonadChainEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](ma GEA, f func(A) either.Either[E, B]) GEB {
return FE.MonadChainEitherK( return FE.MonadChainEitherK(
MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B],
FromEither[GEB, GIOB, R, E, B], FromEither[GEB, GIOB, R, E, B],
@@ -99,39 +99,39 @@ func MonadChainEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Eit
) )
} }
func ChainEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](f func(A) ET.Either[E, B]) func(ma GEA) GEB { func ChainEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](f func(A) either.Either[E, B]) func(ma GEA) GEB {
return F.Bind2nd(MonadChainEitherK[GEA, GEB, GIOA, GIOB, R, E, A, B], f) return F.Bind2nd(MonadChainEitherK[GEA, GEB, GIOA, GIOB, R, E, A, B], f)
} }
func MonadChainFirstEitherK[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A, B any](ma GEA, f func(A) ET.Either[E, B]) GEA { func MonadChainFirstEitherK[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A, B any](ma GEA, f func(A) either.Either[E, B]) GEA {
return FE.MonadChainFirstEitherK( return FE.MonadChainFirstEitherK(
MonadChain[GEA, GEA, GIOA, GIOA, R, E, A, A], MonadChain[GEA, GEA, GIOA, GIOA, R, E, A, A],
MonadMap[func(R) func() ET.Either[E, B], GEA, func() ET.Either[E, B], GIOA, R, E, B, A], MonadMap[func(R) func() either.Either[E, B], GEA, func() either.Either[E, B], GIOA, R, E, B, A],
FromEither[func(R) func() ET.Either[E, B], func() ET.Either[E, B], R, E, B], FromEither[func(R) func() either.Either[E, B], func() either.Either[E, B], R, E, B],
ma, ma,
f, f,
) )
} }
func ChainFirstEitherK[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A, B any](f func(A) ET.Either[E, B]) func(ma GEA) GEA { func ChainFirstEitherK[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A, B any](f func(A) either.Either[E, B]) func(ma GEA) GEA {
return F.Bind2nd(MonadChainFirstEitherK[GEA, GIOA, R, E, A, B], f) return F.Bind2nd(MonadChainFirstEitherK[GEA, GIOA, R, E, A, B], f)
} }
func MonadChainFirstIOK[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GIO ~func() B, R, E, A, B any](ma GEA, f func(A) GIO) GEA { func MonadChainFirstIOK[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GIO ~func() B, R, E, A, B any](ma GEA, f func(A) GIO) GEA {
return FIO.MonadChainFirstIOK( return FIO.MonadChainFirstIOK(
MonadChain[GEA, GEA, GIOA, GIOA, R, E, A, A], MonadChain[GEA, GEA, GIOA, GIOA, R, E, A, A],
MonadMap[func(R) func() ET.Either[E, B], GEA, func() ET.Either[E, B], GIOA, R, E, B, A], MonadMap[func(R) func() either.Either[E, B], GEA, func() either.Either[E, B], GIOA, R, E, B, A],
FromIO[func(R) func() ET.Either[E, B], func() ET.Either[E, B], GIO, R, E, B], FromIO[func(R) func() either.Either[E, B], func() either.Either[E, B], GIO, R, E, B],
ma, ma,
f, f,
) )
} }
func ChainFirstIOK[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GIO ~func() B, R, E, A, B any](f func(A) GIO) func(GEA) GEA { func ChainFirstIOK[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GIO ~func() B, R, E, A, B any](f func(A) GIO) func(GEA) GEA {
return F.Bind2nd(MonadChainFirstIOK[GEA, GIOA, GIO, R, E, A, B], f) return F.Bind2nd(MonadChainFirstIOK[GEA, GIOA, GIO, R, E, A, B], f)
} }
func MonadChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], GB ~func(R) B, R, E, A, B any](ma GEA, f func(A) GB) GEB { func MonadChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], GB ~func(R) B, R, E, A, B any](ma GEA, f func(A) GB) GEB {
return FR.MonadChainReaderK( return FR.MonadChainReaderK(
MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B],
FromReader[GB, GEB, GIOB, R, E, B], FromReader[GB, GEB, GIOB, R, E, B],
@@ -140,7 +140,7 @@ func MonadChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Eit
) )
} }
func ChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], GB ~func(R) B, R, E, A, B any](f func(A) GB) func(GEA) GEB { func ChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], GB ~func(R) B, R, E, A, B any](f func(A) GB) func(GEA) GEB {
return FR.ChainReaderK( return FR.ChainReaderK(
MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B],
FromReader[GB, GEB, GIOB, R, E, B], FromReader[GB, GEB, GIOB, R, E, B],
@@ -148,7 +148,7 @@ func ChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E
) )
} }
func MonadChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() ET.Either[E, A], GIOEB ~func() ET.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](ma GEA, f func(A) GB) GEB { func MonadChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() either.Either[E, A], GIOEB ~func() either.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](ma GEA, f func(A) GB) GEB {
return FR.MonadChainReaderK( return FR.MonadChainReaderK(
MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B], MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B],
RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B], RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B],
@@ -157,7 +157,7 @@ func MonadChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() E
) )
} }
func ChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() ET.Either[E, A], GIOEB ~func() ET.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](f func(A) GB) func(GEA) GEB { func ChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() either.Either[E, A], GIOEB ~func() either.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](f func(A) GB) func(GEA) GEB {
return FR.ChainReaderK( return FR.ChainReaderK(
MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B], MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B],
RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B], RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B],
@@ -165,7 +165,7 @@ func ChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() ET.Eit
) )
} }
func MonadChainIOEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](ma GEA, f func(A) GIOB) GEB { func MonadChainIOEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](ma GEA, f func(A) GIOB) GEB {
return FIOE.MonadChainIOEitherK( return FIOE.MonadChainIOEitherK(
MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B],
FromIOEither[GEB, GIOB, R, E, B], FromIOEither[GEB, GIOB, R, E, B],
@@ -174,11 +174,11 @@ func MonadChainIOEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.E
) )
} }
func ChainIOEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](f func(A) GIOB) func(GEA) GEB { func ChainIOEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](f func(A) GIOB) func(GEA) GEB {
return F.Bind2nd(MonadChainIOEitherK[GEA, GEB, GIOA, GIOB, R, E, A, B], f) return F.Bind2nd(MonadChainIOEitherK[GEA, GEB, GIOA, GIOB, R, E, A, B], f)
} }
func MonadChainIOK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], GIO ~func() B, R, E, A, B any](ma GEA, f func(A) GIO) GEB { func MonadChainIOK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], GIO ~func() B, R, E, A, B any](ma GEA, f func(A) GIO) GEB {
return FIO.MonadChainIOK( return FIO.MonadChainIOK(
MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B],
FromIO[GEB, GIOB, GIO, R, E, B], FromIO[GEB, GIOB, GIO, R, E, B],
@@ -187,11 +187,11 @@ func MonadChainIOK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[
) )
} }
func ChainIOK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], GIO ~func() B, R, E, A, B any](f func(A) GIO) func(GEA) GEB { func ChainIOK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], GIO ~func() B, R, E, A, B any](f func(A) GIO) func(GEA) GEB {
return F.Bind2nd(MonadChainIOK[GEA, GEB, GIOA, GIOB, GIO, R, E, A, B], f) return F.Bind2nd(MonadChainIOK[GEA, GEB, GIOA, GIOB, GIO, R, E, A, B], f)
} }
func ChainOptionK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](onNone func() E) func(func(A) O.Option[B]) func(GEA) GEB { func ChainOptionK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() either.Either[E, A], GIOB ~func() either.Either[E, B], R, E, A, B any](onNone func() E) func(func(A) O.Option[B]) func(GEA) GEB {
return FE.ChainOptionK(MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], FromEither[GEB, GIOB, R, E, B], onNone) return FE.ChainOptionK(MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B], FromEither[GEB, GIOB, R, E, B], onNone)
} }
@@ -199,14 +199,14 @@ func MonadAp[
GEA ~func(R) GIOA, GEA ~func(R) GIOA,
GEB ~func(R) GIOB, GEB ~func(R) GIOB,
GEFAB ~func(R) GIOFAB, GEFAB ~func(R) GIOFAB,
GIOA ~func() ET.Either[E, A], GIOA ~func() either.Either[E, A],
GIOB ~func() ET.Either[E, B], GIOB ~func() either.Either[E, B],
GIOFAB ~func() ET.Either[E, func(A) B], GIOFAB ~func() either.Either[E, func(A) B],
R, E, A, B any](fab GEFAB, fa GEA) GEB { R, E, A, B any](fab GEFAB, fa GEA) GEB {
return eithert.MonadAp( return eithert.MonadAp(
G.MonadAp[GEA, GEB, func(R) func() func(ET.Either[E, A]) ET.Either[E, B], GIOA, GIOB, func() func(ET.Either[E, A]) ET.Either[E, B], R, ET.Either[E, A], ET.Either[E, B]], G.MonadAp[GEA, GEB, func(R) func() func(either.Either[E, A]) either.Either[E, B], GIOA, GIOB, func() func(either.Either[E, A]) either.Either[E, B], R, either.Either[E, A], either.Either[E, B]],
G.MonadMap[GEFAB, func(R) func() func(ET.Either[E, A]) ET.Either[E, B], GIOFAB, func() func(ET.Either[E, A]) ET.Either[E, B], R, ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]], G.MonadMap[GEFAB, func(R) func() func(either.Either[E, A]) either.Either[E, B], GIOFAB, func() func(either.Either[E, A]) either.Either[E, B], R, either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
fab, fab,
fa, fa,
) )
@@ -216,9 +216,9 @@ func Ap[
GEA ~func(R) GIOA, GEA ~func(R) GIOA,
GEB ~func(R) GIOB, GEB ~func(R) GIOB,
GEFAB ~func(R) GIOFAB, GEFAB ~func(R) GIOFAB,
GIOA ~func() ET.Either[E, A], GIOA ~func() either.Either[E, A],
GIOB ~func() ET.Either[E, B], GIOB ~func() either.Either[E, B],
GIOFAB ~func() ET.Either[E, func(A) B], GIOFAB ~func() either.Either[E, func(A) B],
R, E, A, B any](fa GEA) func(fab GEFAB) GEB { R, E, A, B any](fa GEA) func(fab GEFAB) GEB {
return F.Bind2nd(MonadAp[GEA, GEB, GEFAB, GIOA, GIOB, GIOFAB, R, E, A, B], fa) return F.Bind2nd(MonadAp[GEA, GEB, GEFAB, GIOA, GIOB, GIOFAB, R, E, A, B], fa)
} }
@@ -227,14 +227,14 @@ func MonadApSeq[
GEA ~func(R) GIOA, GEA ~func(R) GIOA,
GEB ~func(R) GIOB, GEB ~func(R) GIOB,
GEFAB ~func(R) GIOFAB, GEFAB ~func(R) GIOFAB,
GIOA ~func() ET.Either[E, A], GIOA ~func() either.Either[E, A],
GIOB ~func() ET.Either[E, B], GIOB ~func() either.Either[E, B],
GIOFAB ~func() ET.Either[E, func(A) B], GIOFAB ~func() either.Either[E, func(A) B],
R, E, A, B any](fab GEFAB, fa GEA) GEB { R, E, A, B any](fab GEFAB, fa GEA) GEB {
return eithert.MonadAp( return eithert.MonadAp(
G.MonadApSeq[GEA, GEB, func(R) func() func(ET.Either[E, A]) ET.Either[E, B], GIOA, GIOB, func() func(ET.Either[E, A]) ET.Either[E, B], R, ET.Either[E, A], ET.Either[E, B]], G.MonadApSeq[GEA, GEB, func(R) func() func(either.Either[E, A]) either.Either[E, B], GIOA, GIOB, func() func(either.Either[E, A]) either.Either[E, B], R, either.Either[E, A], either.Either[E, B]],
G.MonadMap[GEFAB, func(R) func() func(ET.Either[E, A]) ET.Either[E, B], GIOFAB, func() func(ET.Either[E, A]) ET.Either[E, B], R, ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]], G.MonadMap[GEFAB, func(R) func() func(either.Either[E, A]) either.Either[E, B], GIOFAB, func() func(either.Either[E, A]) either.Either[E, B], R, either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
fab, fab,
fa, fa,
) )
@@ -244,9 +244,9 @@ func ApSeq[
GEA ~func(R) GIOA, GEA ~func(R) GIOA,
GEB ~func(R) GIOB, GEB ~func(R) GIOB,
GEFAB ~func(R) GIOFAB, GEFAB ~func(R) GIOFAB,
GIOA ~func() ET.Either[E, A], GIOA ~func() either.Either[E, A],
GIOB ~func() ET.Either[E, B], GIOB ~func() either.Either[E, B],
GIOFAB ~func() ET.Either[E, func(A) B], GIOFAB ~func() either.Either[E, func(A) B],
R, E, A, B any](fa GEA) func(fab GEFAB) GEB { R, E, A, B any](fa GEA) func(fab GEFAB) GEB {
return F.Bind2nd(MonadApSeq[GEA, GEB, GEFAB, GIOA, GIOB, GIOFAB, R, E, A, B], fa) return F.Bind2nd(MonadApSeq[GEA, GEB, GEFAB, GIOA, GIOB, GIOFAB, R, E, A, B], fa)
} }
@@ -255,14 +255,14 @@ func MonadApPar[
GEA ~func(R) GIOA, GEA ~func(R) GIOA,
GEB ~func(R) GIOB, GEB ~func(R) GIOB,
GEFAB ~func(R) GIOFAB, GEFAB ~func(R) GIOFAB,
GIOA ~func() ET.Either[E, A], GIOA ~func() either.Either[E, A],
GIOB ~func() ET.Either[E, B], GIOB ~func() either.Either[E, B],
GIOFAB ~func() ET.Either[E, func(A) B], GIOFAB ~func() either.Either[E, func(A) B],
R, E, A, B any](fab GEFAB, fa GEA) GEB { R, E, A, B any](fab GEFAB, fa GEA) GEB {
return eithert.MonadAp( return eithert.MonadAp(
G.MonadApPar[GEA, GEB, func(R) func() func(ET.Either[E, A]) ET.Either[E, B], GIOA, GIOB, func() func(ET.Either[E, A]) ET.Either[E, B], R, ET.Either[E, A], ET.Either[E, B]], G.MonadApPar[GEA, GEB, func(R) func() func(either.Either[E, A]) either.Either[E, B], GIOA, GIOB, func() func(either.Either[E, A]) either.Either[E, B], R, either.Either[E, A], either.Either[E, B]],
G.MonadMap[GEFAB, func(R) func() func(ET.Either[E, A]) ET.Either[E, B], GIOFAB, func() func(ET.Either[E, A]) ET.Either[E, B], R, ET.Either[E, func(A) B], func(ET.Either[E, A]) ET.Either[E, B]], G.MonadMap[GEFAB, func(R) func() func(either.Either[E, A]) either.Either[E, B], GIOFAB, func() func(either.Either[E, A]) either.Either[E, B], R, either.Either[E, func(A) B], func(either.Either[E, A]) either.Either[E, B]],
fab, fab,
fa, fa,
) )
@@ -272,55 +272,55 @@ func ApPar[
GEA ~func(R) GIOA, GEA ~func(R) GIOA,
GEB ~func(R) GIOB, GEB ~func(R) GIOB,
GEFAB ~func(R) GIOFAB, GEFAB ~func(R) GIOFAB,
GIOA ~func() ET.Either[E, A], GIOA ~func() either.Either[E, A],
GIOB ~func() ET.Either[E, B], GIOB ~func() either.Either[E, B],
GIOFAB ~func() ET.Either[E, func(A) B], GIOFAB ~func() either.Either[E, func(A) B],
R, E, A, B any](fa GEA) func(fab GEFAB) GEB { R, E, A, B any](fa GEA) func(fab GEFAB) GEB {
return F.Bind2nd(MonadApPar[GEA, GEB, GEFAB, GIOA, GIOB, GIOFAB, R, E, A, B], fa) return F.Bind2nd(MonadApPar[GEA, GEB, GEFAB, GIOA, GIOB, GIOFAB, R, E, A, B], fa)
} }
func Right[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](a A) GEA { func Right[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](a A) GEA {
return eithert.Right(G.Of[GEA, GIOA, R, ET.Either[E, A]], a) return eithert.Right(G.Of[GEA, GIOA, R, either.Either[E, A]], a)
} }
func Left[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](e E) GEA { func Left[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](e E) GEA {
return eithert.Left(G.Of[GEA, GIOA, R, ET.Either[E, A]], e) return eithert.Left(G.Of[GEA, GIOA, R, either.Either[E, A]], e)
} }
func ThrowError[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](e E) GEA { func ThrowError[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](e E) GEA {
return Left[GEA](e) return Left[GEA](e)
} }
// Of returns a Reader with a fixed value // Of returns a Reader with a fixed value
func Of[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](a A) GEA { func Of[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](a A) GEA {
return Right[GEA](a) return Right[GEA](a)
} }
func Flatten[GEA ~func(R) GIOA, GGEA ~func(R) GIOEA, GIOA ~func() ET.Either[E, A], GIOEA ~func() ET.Either[E, GEA], R, E, A any](mma GGEA) GEA { func Flatten[GEA ~func(R) GIOA, GGEA ~func(R) GIOEA, GIOA ~func() either.Either[E, A], GIOEA ~func() either.Either[E, GEA], R, E, A any](mma GGEA) GEA {
return MonadChain(mma, F.Identity[GEA]) return MonadChain(mma, F.Identity[GEA])
} }
func FromIOEither[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](t GIOA) GEA { func FromIOEither[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](t GIOA) GEA {
return RD.Of[GEA](t) return RD.Of[GEA](t)
} }
func FromEither[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](t ET.Either[E, A]) GEA { func FromEither[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](t either.Either[E, A]) GEA {
return G.Of[GEA](t) return G.Of[GEA](t)
} }
func RightReader[GA ~func(R) A, GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](ma GA) GEA { func RightReader[GA ~func(R) A, GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](ma GA) GEA {
return F.Flow2(ma, IOE.Right[GIOA, E, A]) return F.Flow2(ma, IOE.Right[GIOA, E, A])
} }
func LeftReader[GE ~func(R) E, GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](ma GE) GEA { func LeftReader[GE ~func(R) E, GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](ma GE) GEA {
return F.Flow2(ma, IOE.Left[GIOA, E, A]) return F.Flow2(ma, IOE.Left[GIOA, E, A])
} }
func FromReader[GA ~func(R) A, GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](ma GA) GEA { func FromReader[GA ~func(R) A, GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](ma GA) GEA {
return RightReader[GA, GEA](ma) return RightReader[GA, GEA](ma)
} }
func MonadFromReaderIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GRIO ~func(R) GIO, GIO ~func() A, R, E, A any](a A, f func(A) GRIO) GEA { func MonadFromReaderIO[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GRIO ~func(R) GIO, GIO ~func() A, R, E, A any](a A, f func(A) GRIO) GEA {
return F.Pipe2( return F.Pipe2(
a, a,
f, f,
@@ -328,98 +328,98 @@ func MonadFromReaderIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GRIO ~fu
) )
} }
func FromReaderIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GRIO ~func(R) GIO, GIO ~func() A, R, E, A any](f func(A) GRIO) func(A) GEA { func FromReaderIO[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GRIO ~func(R) GIO, GIO ~func() A, R, E, A any](f func(A) GRIO) func(A) GEA {
return F.Bind2nd(MonadFromReaderIO[GEA, GIOA, GRIO, GIO, R, E, A], f) return F.Bind2nd(MonadFromReaderIO[GEA, GIOA, GRIO, GIO, R, E, A], f)
} }
func RightReaderIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GRIO ~func(R) GIO, GIO ~func() A, R, E, A any](ma GRIO) GEA { func RightReaderIO[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GRIO ~func(R) GIO, GIO ~func() A, R, E, A any](ma GRIO) GEA {
return eithert.RightF( return eithert.RightF(
G.MonadMap[GRIO, GEA, GIO, GIOA, R, A, ET.Either[E, A]], G.MonadMap[GRIO, GEA, GIO, GIOA, R, A, either.Either[E, A]],
ma, ma,
) )
} }
func LeftReaderIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GRIO ~func(R) GIO, GIO ~func() E, R, E, A any](me GRIO) GEA { func LeftReaderIO[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GRIO ~func(R) GIO, GIO ~func() E, R, E, A any](me GRIO) GEA {
return eithert.LeftF( return eithert.LeftF(
G.MonadMap[GRIO, GEA, GIO, GIOA, R, E, ET.Either[E, A]], G.MonadMap[GRIO, GEA, GIO, GIOA, R, E, either.Either[E, A]],
me, me,
) )
} }
func RightIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GR ~func() A, R, E, A any](ma GR) GEA { func RightIO[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GR ~func() A, R, E, A any](ma GR) GEA {
return F.Pipe2(ma, IOE.RightIO[GIOA, GR, E, A], FromIOEither[GEA, GIOA, R, E, A]) return F.Pipe2(ma, IOE.RightIO[GIOA, GR, E, A], FromIOEither[GEA, GIOA, R, E, A])
} }
func LeftIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GR ~func() E, R, E, A any](ma GR) GEA { func LeftIO[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GR ~func() E, R, E, A any](ma GR) GEA {
return F.Pipe2(ma, IOE.LeftIO[GIOA, GR, E, A], FromIOEither[GEA, GIOA, R, E, A]) return F.Pipe2(ma, IOE.LeftIO[GIOA, GR, E, A], FromIOEither[GEA, GIOA, R, E, A])
} }
func FromIO[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], GR ~func() A, R, E, A any](ma GR) GEA { func FromIO[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], GR ~func() A, R, E, A any](ma GR) GEA {
return RightIO[GEA](ma) return RightIO[GEA](ma)
} }
func FromReaderEither[GA ~func(R) ET.Either[E, A], GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](ma GA) GEA { func FromReaderEither[GA ~func(R) either.Either[E, A], GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](ma GA) GEA {
return F.Flow2(ma, IOE.FromEither[GIOA, E, A]) return F.Flow2(ma, IOE.FromEither[GIOA, E, A])
} }
func Ask[GER ~func(R) GIOR, GIOR ~func() ET.Either[E, R], R, E any]() GER { func Ask[GER ~func(R) GIOR, GIOR ~func() either.Either[E, R], R, E any]() GER {
return FR.Ask(FromReader[func(R) R, GER, GIOR, R, E, R])() return FR.Ask(FromReader[func(R) R, GER, GIOR, R, E, R])()
} }
func Asks[GA ~func(R) A, GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](r GA) GEA { func Asks[GA ~func(R) A, GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](r GA) GEA {
return FR.Asks(FromReader[GA, GEA, GIOA, R, E, A])(r) return FR.Asks(FromReader[GA, GEA, GIOA, R, E, A])(r)
} }
func FromOption[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](onNone func() E) func(O.Option[A]) GEA { func FromOption[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](onNone func() E) func(O.Option[A]) GEA {
return FE.FromOption(FromEither[GEA, GIOA, R, E, A], onNone) return FE.FromOption(FromEither[GEA, GIOA, R, E, A], onNone)
} }
func FromPredicate[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](pred func(A) bool, onFalse func(A) E) func(A) GEA { func FromPredicate[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](pred func(A) bool, onFalse func(A) E) func(A) GEA {
return FE.FromPredicate(FromEither[GEA, GIOA, R, E, A], pred, onFalse) return FE.FromPredicate(FromEither[GEA, GIOA, R, E, A], pred, onFalse)
} }
func Fold[GB ~func(R) GIOB, GEA ~func(R) GIOA, GIOB ~func() B, GIOA ~func() ET.Either[E, A], R, E, A, B any](onLeft func(E) GB, onRight func(A) GB) func(GEA) GB { func Fold[GB ~func(R) GIOB, GEA ~func(R) GIOA, GIOB ~func() B, GIOA ~func() either.Either[E, A], R, E, A, B any](onLeft func(E) GB, onRight func(A) GB) func(GEA) GB {
return eithert.MatchE(G.MonadChain[GEA, GB, GIOA, GIOB, R, ET.Either[E, A], B], onLeft, onRight) return eithert.MatchE(G.MonadChain[GEA, GB, GIOA, GIOB, R, either.Either[E, A], B], onLeft, onRight)
} }
func GetOrElse[GA ~func(R) GIOB, GEA ~func(R) GIOA, GIOB ~func() A, GIOA ~func() ET.Either[E, A], R, E, A any](onLeft func(E) GA) func(GEA) GA { func GetOrElse[GA ~func(R) GIOB, GEA ~func(R) GIOA, GIOB ~func() A, GIOA ~func() either.Either[E, A], R, E, A any](onLeft func(E) GA) func(GEA) GA {
return eithert.GetOrElse(G.MonadChain[GEA, GA, GIOA, GIOB, R, ET.Either[E, A], A], G.Of[GA, GIOB, R, A], onLeft) return eithert.GetOrElse(G.MonadChain[GEA, GA, GIOA, GIOB, R, either.Either[E, A], A], G.Of[GA, GIOB, R, A], onLeft)
} }
func OrElse[GEA1 ~func(R) GIOA1, GEA2 ~func(R) GIOA2, GIOA1 ~func() ET.Either[E1, A], GIOA2 ~func() ET.Either[E2, A], R, E1, A, E2 any](onLeft func(E1) GEA2) func(GEA1) GEA2 { func OrElse[GEA1 ~func(R) GIOA1, GEA2 ~func(R) GIOA2, GIOA1 ~func() either.Either[E1, A], GIOA2 ~func() either.Either[E2, A], R, E1, A, E2 any](onLeft func(E1) GEA2) func(GEA1) GEA2 {
return eithert.OrElse(G.MonadChain[GEA1, GEA2, GIOA1, GIOA2, R, ET.Either[E1, A], ET.Either[E2, A]], G.Of[GEA2, GIOA2, R, ET.Either[E2, A]], onLeft) return eithert.OrElse(G.MonadChain[GEA1, GEA2, GIOA1, GIOA2, R, either.Either[E1, A], either.Either[E2, A]], G.Of[GEA2, GIOA2, R, either.Either[E2, A]], onLeft)
} }
func OrLeft[GEA1 ~func(R) GIOA1, GE2 ~func(R) GIOE2, GEA2 ~func(R) GIOA2, GIOA1 ~func() ET.Either[E1, A], GIOE2 ~func() E2, GIOA2 ~func() ET.Either[E2, A], E1, R, E2, A any](onLeft func(E1) GE2) func(GEA1) GEA2 { func OrLeft[GEA1 ~func(R) GIOA1, GE2 ~func(R) GIOE2, GEA2 ~func(R) GIOA2, GIOA1 ~func() either.Either[E1, A], GIOE2 ~func() E2, GIOA2 ~func() either.Either[E2, A], E1, R, E2, A any](onLeft func(E1) GE2) func(GEA1) GEA2 {
return eithert.OrLeft( return eithert.OrLeft(
G.MonadChain[GEA1, GEA2, GIOA1, GIOA2, R, ET.Either[E1, A], ET.Either[E2, A]], G.MonadChain[GEA1, GEA2, GIOA1, GIOA2, R, either.Either[E1, A], either.Either[E2, A]],
G.MonadMap[GE2, GEA2, GIOE2, GIOA2, R, E2, ET.Either[E2, A]], G.MonadMap[GE2, GEA2, GIOE2, GIOA2, R, E2, either.Either[E2, A]],
G.Of[GEA2, GIOA2, R, ET.Either[E2, A]], G.Of[GEA2, GIOA2, R, either.Either[E2, A]],
onLeft, onLeft,
) )
} }
func MonadBiMap[GA ~func(R) GE1A, GB ~func(R) GE2B, GE1A ~func() ET.Either[E1, A], GE2B ~func() ET.Either[E2, B], R, E1, E2, A, B any](fa GA, f func(E1) E2, g func(A) B) GB { func MonadBiMap[GA ~func(R) GE1A, GB ~func(R) GE2B, GE1A ~func() either.Either[E1, A], GE2B ~func() either.Either[E2, B], R, E1, E2, A, B any](fa GA, f func(E1) E2, g func(A) B) GB {
return eithert.MonadBiMap(G.MonadMap[GA, GB, GE1A, GE2B, R, ET.Either[E1, A], ET.Either[E2, B]], fa, f, g) return eithert.MonadBiMap(G.MonadMap[GA, GB, GE1A, GE2B, R, 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.
func BiMap[GA ~func(R) GE1A, GB ~func(R) GE2B, GE1A ~func() ET.Either[E1, A], GE2B ~func() ET.Either[E2, B], R, E1, E2, A, B any](f func(E1) E2, g func(A) B) func(GA) GB { func BiMap[GA ~func(R) GE1A, GB ~func(R) GE2B, GE1A ~func() either.Either[E1, A], GE2B ~func() either.Either[E2, B], R, E1, E2, A, B any](f func(E1) E2, g func(A) B) func(GA) GB {
return eithert.BiMap(G.Map[GA, GB, GE1A, GE2B, R, ET.Either[E1, A], ET.Either[E2, B]], f, g) return eithert.BiMap(G.Map[GA, GB, GE1A, GE2B, R, either.Either[E1, A], either.Either[E2, B]], f, g)
} }
// Swap changes the order of type parameters // Swap changes the order of type parameters
func Swap[GREA ~func(R) GEA, GRAE ~func(R) GAE, GEA ~func() ET.Either[E, A], GAE ~func() ET.Either[A, E], R, E, A any](val GREA) GRAE { func Swap[GREA ~func(R) GEA, GRAE ~func(R) GAE, GEA ~func() either.Either[E, A], GAE ~func() either.Either[A, E], R, E, A any](val GREA) GRAE {
return RD.MonadMap[GREA, GRAE, R, GEA, GAE](val, IOE.Swap[GEA, GAE]) return RD.MonadMap[GREA, GRAE, R, GEA, GAE](val, IOE.Swap[GEA, GAE])
} }
// 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
func Defer[GEA ~func(R) GA, GA ~func() ET.Either[E, A], R, E, A any](gen func() GEA) GEA { func Defer[GEA ~func(R) GA, GA ~func() either.Either[E, A], R, E, A any](gen func() GEA) GEA {
return G.Defer[GEA](gen) return G.Defer[GEA](gen)
} }
// TryCatch wraps a reader returning a tuple as an error into ReaderIOEither // TryCatch wraps a reader returning a tuple as an error into ReaderIOEither
func TryCatch[GEA ~func(R) GA, GA ~func() ET.Either[E, A], R, E, A any](f func(R) func() (A, error), onThrow func(error) E) GEA { func TryCatch[GEA ~func(R) GA, GA ~func() either.Either[E, A], R, E, A any](f func(R) func() (A, error), onThrow func(error) E) GEA {
return func(r R) GA { return func(r R) GA {
return IOE.TryCatch[GA](f(r), onThrow) return IOE.TryCatch[GA](f(r), onThrow)
} }
@@ -429,24 +429,24 @@ func TryCatch[GEA ~func(R) GA, GA ~func() ET.Either[E, A], R, E, A any](f func(R
// The context used to compute the value is the context of the first call, so do not use this // The context used to compute the value is the context of the first call, so do not use this
// method if the value has a functional dependency on the content of the context // method if the value has a functional dependency on the content of the context
func Memoize[ func Memoize[
GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](rdr GEA) GEA { GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](rdr GEA) GEA {
return G.Memoize[GEA](rdr) return G.Memoize[GEA](rdr)
} }
func MonadFlap[GREAB ~func(R) GEAB, GREB ~func(R) GEB, GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], R, E, B, A any](fab GREAB, a A) GREB { func MonadFlap[GREAB ~func(R) GEAB, GREB ~func(R) GEB, GEAB ~func() either.Either[E, func(A) B], GEB ~func() either.Either[E, B], R, E, B, A any](fab GREAB, a A) GREB {
return FC.MonadFlap(MonadMap[GREAB, GREB], fab, a) return FC.MonadFlap(MonadMap[GREAB, GREB], fab, a)
} }
func Flap[GREAB ~func(R) GEAB, GREB ~func(R) GEB, GEAB ~func() ET.Either[E, func(A) B], GEB ~func() ET.Either[E, B], R, E, B, A any](a A) func(GREAB) GREB { func Flap[GREAB ~func(R) GEAB, GREB ~func(R) GEB, GEAB ~func() either.Either[E, func(A) B], GEB ~func() either.Either[E, B], R, E, B, A any](a A) func(GREAB) GREB {
return FC.Flap(Map[GREAB, GREB], a) return FC.Flap(Map[GREAB, GREB], a)
} }
func MonadMapLeft[GREA1 ~func(R) GEA1, GREA2 ~func(R) GEA2, GEA1 ~func() ET.Either[E1, A], GEA2 ~func() ET.Either[E2, A], R, E1, E2, A any](fa GREA1, f func(E1) E2) GREA2 { func MonadMapLeft[GREA1 ~func(R) GEA1, GREA2 ~func(R) GEA2, GEA1 ~func() either.Either[E1, A], GEA2 ~func() either.Either[E2, A], R, E1, E2, A any](fa GREA1, f func(E1) E2) GREA2 {
return eithert.MonadMapLeft(G.MonadMap[GREA1, GREA2], fa, f) return eithert.MonadMapLeft(G.MonadMap[GREA1, GREA2], fa, f)
} }
// MapLeft applies a mapping function to the error channel // MapLeft applies a mapping function to the error channel
func MapLeft[GREA1 ~func(R) GEA1, GREA2 ~func(R) GEA2, GEA1 ~func() ET.Either[E1, A], GEA2 ~func() ET.Either[E2, A], R, E1, E2, A any](f func(E1) E2) func(GREA1) GREA2 { func MapLeft[GREA1 ~func(R) GEA1, GREA2 ~func(R) GEA2, GEA1 ~func() either.Either[E1, A], GEA2 ~func() either.Either[E2, A], R, E1, E2, A any](f func(E1) E2) func(GREA1) GREA2 {
return F.Bind2nd(MonadMapLeft[GREA1, GREA2], f) return F.Bind2nd(MonadMapLeft[GREA1, GREA2], f)
} }
@@ -456,7 +456,7 @@ func Local[
GEA1 ~func(R1) GIOA, GEA1 ~func(R1) GIOA,
GEA2 ~func(R2) GIOA, GEA2 ~func(R2) GIOA,
GIOA ~func() ET.Either[E, A], GIOA ~func() either.Either[E, A],
R1, R2, E, A any, R1, R2, E, A any,
](f func(R2) R1) func(GEA1) GEA2 { ](f func(R2) R1) func(GEA1) GEA2 {
return RD.Local[GEA1, GEA2](f) return RD.Local[GEA1, GEA2](f)

View File

@@ -1,48 +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"
IOE "github.com/IBM/fp-go/v2/ioeither/generic"
)
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource
func WithResource[
GEA ~func(L) TEA,
GER ~func(L) TER,
GEANY ~func(L) TEANY,
TEA ~func() ET.Either[E, A],
TER ~func() ET.Either[E, R],
TEANY ~func() ET.Either[E, ANY],
L, E, R, A, ANY any](onCreate GER, onRelease func(R) GEANY) func(func(R) GEA) GEA {
return func(f func(R) GEA) GEA {
return func(l L) TEA {
// dispatch to the generic implementation
return IOE.WithResource[TEA](
onCreate(l),
func(r R) TEANY {
return onRelease(r)(l)
},
)(func(r R) TEA {
return f(r)(l)
})
}
}
}

View File

@@ -16,7 +16,7 @@
package generic package generic
import ( import (
ET "github.com/IBM/fp-go/v2/either" "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/internal/apply" "github.com/IBM/fp-go/v2/internal/apply"
T "github.com/IBM/fp-go/v2/tuple" T "github.com/IBM/fp-go/v2/tuple"
) )
@@ -26,8 +26,8 @@ import (
func SequenceT1[ func SequenceT1[
GA ~func(E) GIOA, GA ~func(E) GIOA,
GTA ~func(E) GIOTA, GTA ~func(E) GIOTA,
GIOA ~func() ET.Either[L, A], GIOA ~func() either.Either[L, A],
GIOTA ~func() ET.Either[L, T.Tuple1[A]], GIOTA ~func() either.Either[L, T.Tuple1[A]],
E, L, A any](a GA) GTA { E, L, A any](a GA) GTA {
return apply.SequenceT1( return apply.SequenceT1(
Map[GA, GTA, GIOA, GIOTA, E, L, A, T.Tuple1[A]], Map[GA, GTA, GIOA, GIOTA, E, L, A, T.Tuple1[A]],
@@ -40,13 +40,13 @@ func SequenceT2[
GA ~func(E) GIOA, GA ~func(E) GIOA,
GB ~func(E) GIOB, GB ~func(E) GIOB,
GTAB ~func(E) GIOTAB, GTAB ~func(E) GIOTAB,
GIOA ~func() ET.Either[L, A], GIOA ~func() either.Either[L, A],
GIOB ~func() ET.Either[L, B], GIOB ~func() either.Either[L, B],
GIOTAB ~func() ET.Either[L, T.Tuple2[A, B]], GIOTAB ~func() either.Either[L, T.Tuple2[A, B]],
E, L, A, B any](a GA, b GB) GTAB { E, L, A, B any](a GA, b GB) GTAB {
return apply.SequenceT2( return apply.SequenceT2(
Map[GA, func(E) func() ET.Either[L, func(B) T.Tuple2[A, B]], GIOA, func() ET.Either[L, func(B) T.Tuple2[A, B]], E, L, A, func(B) T.Tuple2[A, B]], Map[GA, func(E) func() either.Either[L, func(B) T.Tuple2[A, B]], GIOA, func() either.Either[L, func(B) T.Tuple2[A, B]], E, L, A, func(B) T.Tuple2[A, B]],
Ap[GB, GTAB, func(E) func() ET.Either[L, func(B) T.Tuple2[A, B]], GIOB, GIOTAB, func() ET.Either[L, func(B) T.Tuple2[A, B]], E, L, B, T.Tuple2[A, B]], Ap[GB, GTAB, func(E) func() either.Either[L, func(B) T.Tuple2[A, B]], GIOB, GIOTAB, func() either.Either[L, func(B) T.Tuple2[A, B]], E, L, B, T.Tuple2[A, B]],
a, b, a, b,
) )
@@ -57,15 +57,15 @@ func SequenceT3[
GB ~func(E) GIOB, GB ~func(E) GIOB,
GC ~func(E) GIOC, GC ~func(E) GIOC,
GTABC ~func(E) GIOTABC, GTABC ~func(E) GIOTABC,
GIOA ~func() ET.Either[L, A], GIOA ~func() either.Either[L, A],
GIOB ~func() ET.Either[L, B], GIOB ~func() either.Either[L, B],
GIOC ~func() ET.Either[L, C], GIOC ~func() either.Either[L, C],
GIOTABC ~func() ET.Either[L, T.Tuple3[A, B, C]], GIOTABC ~func() either.Either[L, T.Tuple3[A, B, C]],
E, L, A, B, C any](a GA, b GB, c GC) GTABC { E, L, A, B, C any](a GA, b GB, c GC) GTABC {
return apply.SequenceT3( return apply.SequenceT3(
Map[GA, func(E) func() ET.Either[L, func(B) func(C) T.Tuple3[A, B, C]], GIOA, func() ET.Either[L, func(B) func(C) T.Tuple3[A, B, C]], E, L, A, func(B) func(C) T.Tuple3[A, B, C]], Map[GA, func(E) func() either.Either[L, func(B) func(C) T.Tuple3[A, B, C]], GIOA, func() either.Either[L, func(B) func(C) T.Tuple3[A, B, C]], E, L, A, func(B) func(C) T.Tuple3[A, B, C]],
Ap[GB, func(E) func() ET.Either[L, func(C) T.Tuple3[A, B, C]], func(E) func() ET.Either[L, func(B) func(C) T.Tuple3[A, B, C]], GIOB, func() ET.Either[L, func(C) T.Tuple3[A, B, C]], func() ET.Either[L, func(B) func(C) T.Tuple3[A, B, C]], E, L, B, func(C) T.Tuple3[A, B, C]], Ap[GB, func(E) func() either.Either[L, func(C) T.Tuple3[A, B, C]], func(E) func() either.Either[L, func(B) func(C) T.Tuple3[A, B, C]], GIOB, func() either.Either[L, func(C) T.Tuple3[A, B, C]], func() either.Either[L, func(B) func(C) T.Tuple3[A, B, C]], E, L, B, func(C) T.Tuple3[A, B, C]],
Ap[GC, GTABC, func(E) func() ET.Either[L, func(C) T.Tuple3[A, B, C]], GIOC, GIOTABC, func() ET.Either[L, func(C) T.Tuple3[A, B, C]], E, L, C, T.Tuple3[A, B, C]], Ap[GC, GTABC, func(E) func() either.Either[L, func(C) T.Tuple3[A, B, C]], GIOC, GIOTABC, func() either.Either[L, func(C) T.Tuple3[A, B, C]], E, L, C, T.Tuple3[A, B, C]],
a, b, c, a, b, c,
) )
@@ -77,17 +77,17 @@ func SequenceT4[
GC ~func(E) GIOC, GC ~func(E) GIOC,
GD ~func(E) GIOD, GD ~func(E) GIOD,
GTABCD ~func(E) GIOTABCD, GTABCD ~func(E) GIOTABCD,
GIOA ~func() ET.Either[L, A], GIOA ~func() either.Either[L, A],
GIOB ~func() ET.Either[L, B], GIOB ~func() either.Either[L, B],
GIOC ~func() ET.Either[L, C], GIOC ~func() either.Either[L, C],
GIOD ~func() ET.Either[L, D], GIOD ~func() either.Either[L, D],
GIOTABCD ~func() ET.Either[L, T.Tuple4[A, B, C, D]], GIOTABCD ~func() either.Either[L, T.Tuple4[A, B, C, D]],
E, L, A, B, C, D any](a GA, b GB, c GC, d GD) GTABCD { E, L, A, B, C, D any](a GA, b GB, c GC, d GD) GTABCD {
return apply.SequenceT4( return apply.SequenceT4(
Map[GA, func(E) func() ET.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], GIOA, func() ET.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], E, L, A, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], Map[GA, func(E) func() either.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], GIOA, func() either.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], E, L, A, func(B) func(C) func(D) T.Tuple4[A, B, C, D]],
Ap[GB, func(E) func() ET.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], func(E) func() ET.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], GIOB, func() ET.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], func() ET.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], E, L, B, func(C) func(D) T.Tuple4[A, B, C, D]], Ap[GB, func(E) func() either.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], func(E) func() either.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], GIOB, func() either.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], func() either.Either[L, func(B) func(C) func(D) T.Tuple4[A, B, C, D]], E, L, B, func(C) func(D) T.Tuple4[A, B, C, D]],
Ap[GC, func(E) func() ET.Either[L, func(D) T.Tuple4[A, B, C, D]], func(E) func() ET.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], GIOC, func() ET.Either[L, func(D) T.Tuple4[A, B, C, D]], func() ET.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], E, L, C, func(D) T.Tuple4[A, B, C, D]], Ap[GC, func(E) func() either.Either[L, func(D) T.Tuple4[A, B, C, D]], func(E) func() either.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], GIOC, func() either.Either[L, func(D) T.Tuple4[A, B, C, D]], func() either.Either[L, func(C) func(D) T.Tuple4[A, B, C, D]], E, L, C, func(D) T.Tuple4[A, B, C, D]],
Ap[GD, GTABCD, func(E) func() ET.Either[L, func(D) T.Tuple4[A, B, C, D]], GIOD, GIOTABCD, func() ET.Either[L, func(D) T.Tuple4[A, B, C, D]], E, L, D, T.Tuple4[A, B, C, D]], Ap[GD, GTABCD, func(E) func() either.Either[L, func(D) T.Tuple4[A, B, C, D]], GIOD, GIOTABCD, func() either.Either[L, func(D) T.Tuple4[A, B, C, D]], E, L, D, T.Tuple4[A, B, C, D]],
a, b, c, d, a, b, c, d,
) )

View File

@@ -18,11 +18,11 @@ package generic
import ( import (
"context" "context"
ET "github.com/IBM/fp-go/v2/either" "github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/readerio/generic" G "github.com/IBM/fp-go/v2/readerio/generic"
) )
// WithLock executes the provided IO operation in the scope of a lock // WithLock executes the provided IO operation in the scope of a lock
func WithLock[GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](lock func() context.CancelFunc) func(fa GEA) GEA { func WithLock[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](lock func() context.CancelFunc) func(fa GEA) GEA {
return G.WithLock[GEA](lock) return G.WithLock[GEA](lock)
} }

View File

@@ -16,56 +16,56 @@
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(E) GIOB, GBS ~func(E) GIOBS, GIOB ~func() ET.Either[L, B], GIOBS ~func() ET.Either[L, BBS], AAS ~[]A, BBS ~[]B, E, L, A, B any](ma AAS, f func(A) GB) GBS { func MonadTraverseArray[GB ~func(E) GIOB, GBS ~func(E) GIOBS, GIOB ~func() either.Either[L, B], GIOBS ~func() either.Either[L, BBS], AAS ~[]A, BBS ~[]B, E, L, A, B any](ma AAS, f func(A) GB) GBS {
return RA.MonadTraverse[AAS]( return RA.MonadTraverse[AAS](
Of[GBS, GIOBS, E, L, BBS], Of[GBS, GIOBS, E, L, BBS],
Map[GBS, func(E) func() ET.Either[L, func(B) BBS], GIOBS, func() ET.Either[L, func(B) BBS], E, L, BBS, func(B) BBS], Map[GBS, func(E) func() either.Either[L, func(B) BBS], GIOBS, func() either.Either[L, func(B) BBS], E, L, BBS, func(B) BBS],
Ap[GB, GBS, func(E) func() ET.Either[L, func(B) BBS], GIOB, GIOBS, func() ET.Either[L, func(B) BBS], E, L, B, BBS], Ap[GB, GBS, func(E) func() either.Either[L, func(B) BBS], GIOB, GIOBS, func() either.Either[L, func(B) BBS], E, L, B, BBS],
ma, f, ma, f,
) )
} }
// TraverseArray transforms an array // TraverseArray transforms an array
func TraverseArray[GB ~func(E) GIOB, GBS ~func(E) GIOBS, GIOB ~func() ET.Either[L, B], GIOBS ~func() ET.Either[L, BBS], AAS ~[]A, BBS ~[]B, E, L, A, B any](f func(A) GB) func(AAS) GBS { func TraverseArray[GB ~func(E) GIOB, GBS ~func(E) GIOBS, GIOB ~func() either.Either[L, B], GIOBS ~func() either.Either[L, BBS], AAS ~[]A, BBS ~[]B, E, L, A, B any](f func(A) GB) func(AAS) GBS {
return RA.Traverse[AAS]( return RA.Traverse[AAS](
Of[GBS, GIOBS, E, L, BBS], Of[GBS, GIOBS, E, L, BBS],
Map[GBS, func(E) func() ET.Either[L, func(B) BBS], GIOBS, func() ET.Either[L, func(B) BBS], E, L, BBS, func(B) BBS], Map[GBS, func(E) func() either.Either[L, func(B) BBS], GIOBS, func() either.Either[L, func(B) BBS], E, L, BBS, func(B) BBS],
Ap[GB, GBS, func(E) func() ET.Either[L, func(B) BBS], GIOB, GIOBS, func() ET.Either[L, func(B) BBS], E, L, B, BBS], Ap[GB, GBS, func(E) func() either.Either[L, func(B) BBS], GIOB, GIOBS, func() either.Either[L, func(B) BBS], E, L, B, BBS],
f, f,
) )
} }
// TraverseArrayWithIndex transforms an array // TraverseArrayWithIndex transforms an array
func TraverseArrayWithIndex[GB ~func(E) GIOB, GBS ~func(E) GIOBS, GIOB ~func() ET.Either[L, B], GIOBS ~func() ET.Either[L, BBS], AAS ~[]A, BBS ~[]B, E, L, A, B any](f func(int, A) GB) func(AAS) GBS { func TraverseArrayWithIndex[GB ~func(E) GIOB, GBS ~func(E) GIOBS, GIOB ~func() either.Either[L, B], GIOBS ~func() either.Either[L, BBS], AAS ~[]A, BBS ~[]B, E, L, A, B any](f func(int, A) GB) func(AAS) GBS {
return RA.TraverseWithIndex[AAS]( return RA.TraverseWithIndex[AAS](
Of[GBS, GIOBS, E, L, BBS], Of[GBS, GIOBS, E, L, BBS],
Map[GBS, func(E) func() ET.Either[L, func(B) BBS], GIOBS, func() ET.Either[L, func(B) BBS], E, L, BBS, func(B) BBS], Map[GBS, func(E) func() either.Either[L, func(B) BBS], GIOBS, func() either.Either[L, func(B) BBS], E, L, BBS, func(B) BBS],
Ap[GB, GBS, func(E) func() ET.Either[L, func(B) BBS], GIOB, GIOBS, func() ET.Either[L, func(B) BBS], E, L, B, BBS], Ap[GB, GBS, func(E) func() either.Either[L, func(B) BBS], GIOB, GIOBS, func() either.Either[L, func(B) BBS], E, L, B, BBS],
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(E) GIOA, GAS ~func(E) GIOAS, GIOA ~func() ET.Either[L, A], GIOAS ~func() ET.Either[L, AAS], AAS ~[]A, GAAS ~[]GA, E, L, A any](ma GAAS) GAS { func SequenceArray[GA ~func(E) GIOA, GAS ~func(E) GIOAS, GIOA ~func() either.Either[L, A], GIOAS ~func() either.Either[L, AAS], AAS ~[]A, GAAS ~[]GA, E, L, A any](ma GAAS) GAS {
return MonadTraverseArray[GA, GAS](ma, F.Identity[GA]) return MonadTraverseArray[GA, GAS](ma, F.Identity[GA])
} }
// MonadTraverseRecord transforms an array // MonadTraverseRecord transforms an array
func MonadTraverseRecord[GB ~func(C) GIOB, GBS ~func(C) GIOBS, GIOB ~func() ET.Either[E, B], GIOBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, C, E, A, B any](tas AAS, f func(A) GB) GBS { func MonadTraverseRecord[GB ~func(C) GIOB, GBS ~func(C) GIOBS, GIOB ~func() either.Either[E, B], GIOBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, C, E, A, B any](tas AAS, f func(A) GB) GBS {
return RR.MonadTraverse[AAS]( return RR.MonadTraverse[AAS](
Of[GBS, GIOBS, C, E, BBS], Of[GBS, GIOBS, C, E, BBS],
Map[GBS, func(C) func() ET.Either[E, func(B) BBS], GIOBS, func() ET.Either[E, func(B) BBS], C, E, BBS, func(B) BBS], Map[GBS, func(C) func() either.Either[E, func(B) BBS], GIOBS, func() either.Either[E, func(B) BBS], C, E, BBS, func(B) BBS],
Ap[GB, GBS, func(C) func() ET.Either[E, func(B) BBS], GIOB, GIOBS, func() ET.Either[E, func(B) BBS], C, E, B, BBS], Ap[GB, GBS, func(C) func() either.Either[E, func(B) BBS], GIOB, GIOBS, func() either.Either[E, func(B) BBS], C, E, B, BBS],
tas, tas,
f, f,
@@ -73,28 +73,28 @@ func MonadTraverseRecord[GB ~func(C) GIOB, GBS ~func(C) GIOBS, GIOB ~func() ET.E
} }
// TraverseRecord transforms a record // TraverseRecord transforms a record
func TraverseRecord[GB ~func(C) GIOB, GBS ~func(C) GIOBS, GIOB ~func() ET.Either[E, B], GIOBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, C, E, A, B any](f func(A) GB) func(AAS) GBS { func TraverseRecord[GB ~func(C) GIOB, GBS ~func(C) GIOBS, GIOB ~func() either.Either[E, B], GIOBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, C, E, A, B any](f func(A) GB) func(AAS) GBS {
return RR.Traverse[AAS]( return RR.Traverse[AAS](
Of[GBS, GIOBS, C, E, BBS], Of[GBS, GIOBS, C, E, BBS],
Map[GBS, func(C) func() ET.Either[E, func(B) BBS], GIOBS, func() ET.Either[E, func(B) BBS], C, E, BBS, func(B) BBS], Map[GBS, func(C) func() either.Either[E, func(B) BBS], GIOBS, func() either.Either[E, func(B) BBS], C, E, BBS, func(B) BBS],
Ap[GB, GBS, func(C) func() ET.Either[E, func(B) BBS], GIOB, GIOBS, func() ET.Either[E, func(B) BBS], C, E, B, BBS], Ap[GB, GBS, func(C) func() either.Either[E, func(B) BBS], GIOB, GIOBS, func() either.Either[E, func(B) BBS], C, E, B, BBS],
f, f,
) )
} }
// TraverseRecordWithIndex transforms a record // TraverseRecordWithIndex transforms a record
func TraverseRecordWithIndex[GB ~func(C) GIOB, GBS ~func(C) GIOBS, GIOB ~func() ET.Either[E, B], GIOBS ~func() ET.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, C, E, A, B any](f func(K, A) GB) func(AAS) GBS { func TraverseRecordWithIndex[GB ~func(C) GIOB, GBS ~func(C) GIOBS, GIOB ~func() either.Either[E, B], GIOBS ~func() either.Either[E, BBS], AAS ~map[K]A, BBS ~map[K]B, K comparable, C, E, A, B any](f func(K, A) GB) func(AAS) GBS {
return RR.TraverseWithIndex[AAS]( return RR.TraverseWithIndex[AAS](
Of[GBS, GIOBS, C, E, BBS], Of[GBS, GIOBS, C, E, BBS],
Map[GBS, func(C) func() ET.Either[E, func(B) BBS], GIOBS, func() ET.Either[E, func(B) BBS], C, E, BBS, func(B) BBS], Map[GBS, func(C) func() either.Either[E, func(B) BBS], GIOBS, func() either.Either[E, func(B) BBS], C, E, BBS, func(B) BBS],
Ap[GB, GBS, func(C) func() ET.Either[E, func(B) BBS], GIOB, GIOBS, func() ET.Either[E, func(B) BBS], C, E, B, BBS], Ap[GB, GBS, func(C) func() either.Either[E, func(B) BBS], GIOB, GIOBS, func() either.Either[E, func(B) BBS], C, E, B, BBS],
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(C) GIOA, GAS ~func(C) GIOAS, GIOA ~func() ET.Either[E, A], GIOAS ~func() ET.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, C, E, A any](tas GAAS) GAS { func SequenceRecord[GA ~func(C) GIOA, GAS ~func(C) GIOAS, GIOA ~func() either.Either[E, A], GIOAS ~func() either.Either[E, AAS], AAS ~map[K]A, GAAS ~map[K]GA, K comparable, C, E, A any](tas GAAS) GAS {
return MonadTraverseRecord[GA, GAS](tas, F.Identity[GA]) return MonadTraverseRecord[GA, GAS](tas, F.Identity[GA])
} }

View File

@@ -16,85 +16,115 @@
package readerioeither package readerioeither
import ( import (
ET "github.com/IBM/fp-go/v2/either" "github.com/IBM/fp-go/v2/either"
"github.com/IBM/fp-go/v2/function"
"github.com/IBM/fp-go/v2/internal/chain"
"github.com/IBM/fp-go/v2/internal/eithert"
"github.com/IBM/fp-go/v2/internal/fromeither"
"github.com/IBM/fp-go/v2/io" "github.com/IBM/fp-go/v2/io"
IOE "github.com/IBM/fp-go/v2/ioeither" IOE "github.com/IBM/fp-go/v2/ioeither"
L "github.com/IBM/fp-go/v2/lazy" L "github.com/IBM/fp-go/v2/lazy"
O "github.com/IBM/fp-go/v2/option" O "github.com/IBM/fp-go/v2/option"
RD "github.com/IBM/fp-go/v2/reader" "github.com/IBM/fp-go/v2/reader"
RE "github.com/IBM/fp-go/v2/readereither" RE "github.com/IBM/fp-go/v2/readereither"
RIO "github.com/IBM/fp-go/v2/readerio" "github.com/IBM/fp-go/v2/readerio"
G "github.com/IBM/fp-go/v2/readerioeither/generic" G "github.com/IBM/fp-go/v2/readerioeither/generic"
) )
type ReaderIOEither[R, E, A any] RD.Reader[R, IOE.IOEither[E, A]] type (
ReaderIOEither[R, E, A any] = reader.Reader[R, IOE.IOEither[E, A]]
// MakeReader constructs an instance of a reader Mapper[R, E, A, B any] = reader.Reader[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]]
func MakeReader[R, E, A any](f func(R) IOE.IOEither[E, A]) ReaderIOEither[R, E, A] { )
return G.MakeReader[ReaderIOEither[R, E, A]](f)
func MonadFromReaderIO[R, E, A any](a A, f func(A) readerio.ReaderIO[R, A]) ReaderIOEither[R, E, A] {
return function.Pipe2(
a,
f,
RightReaderIO[R, E, A],
)
} }
func MonadFromReaderIO[R, E, A any](a A, f func(A) RIO.ReaderIO[R, A]) ReaderIOEither[R, E, A] { func FromReaderIO[R, E, A any](f func(A) readerio.ReaderIO[R, A]) func(A) ReaderIOEither[R, E, A] {
return G.MonadFromReaderIO[ReaderIOEither[R, E, A]](a, f) return function.Bind2nd(MonadFromReaderIO[R, E, A], f)
} }
func FromReaderIO[R, E, A any](f func(A) RIO.ReaderIO[R, A]) func(A) ReaderIOEither[R, E, A] { func RightReaderIO[R, E, A any](ma readerio.ReaderIO[R, A]) ReaderIOEither[R, E, A] {
return G.FromReaderIO[ReaderIOEither[R, E, A]](f) return eithert.RightF(
readerio.MonadMap[R, A, either.Either[E, A]],
ma,
)
} }
func RightReaderIO[R, E, A any](ma RIO.ReaderIO[R, A]) ReaderIOEither[R, E, A] { func LeftReaderIO[A, R, E any](me readerio.ReaderIO[R, E]) ReaderIOEither[R, E, A] {
return G.RightReaderIO[ReaderIOEither[R, E, A]](ma) return eithert.LeftF(
} readerio.MonadMap[R, E, either.Either[E, A]],
me,
func LeftReaderIO[A, R, E any](me RIO.ReaderIO[R, E]) ReaderIOEither[R, E, A] { )
return G.LeftReaderIO[ReaderIOEither[R, E, A]](me)
} }
func MonadMap[R, E, A, B any](fa ReaderIOEither[R, E, A], f func(A) B) ReaderIOEither[R, E, B] { func MonadMap[R, E, A, B any](fa ReaderIOEither[R, E, A], f func(A) B) ReaderIOEither[R, E, B] {
return G.MonadMap[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](fa, f) return eithert.MonadMap(readerio.MonadMap[R, either.Either[E, A], either.Either[E, B]], fa, f)
} }
func Map[R, E, A, B any](f func(A) B) func(fa ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] { func Map[R, E, A, B any](f func(A) B) func(fa ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] {
return G.Map[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](f) return eithert.Map(readerio.Map[R, either.Either[E, A], either.Either[E, B]], f)
} }
func MonadMapTo[R, E, A, B any](fa ReaderIOEither[R, E, A], b B) ReaderIOEither[R, E, B] { func MonadMapTo[R, E, A, B any](fa ReaderIOEither[R, E, A], b B) ReaderIOEither[R, E, B] {
return G.MonadMapTo[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](fa, b) return MonadMap(fa, function.Constant1[A](b))
} }
func MapTo[R, E, A, B any](b B) func(ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] { func MapTo[R, E, A, B any](b B) func(ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] {
return G.MapTo[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](b) return Map[R, E](function.Constant1[A](b))
} }
func MonadChain[R, E, A, B any](fa ReaderIOEither[R, E, A], f func(A) ReaderIOEither[R, E, B]) ReaderIOEither[R, E, B] { func MonadChain[R, E, A, B any](fa ReaderIOEither[R, E, A], f func(A) ReaderIOEither[R, E, B]) ReaderIOEither[R, E, B] {
return G.MonadChain(fa, f) return eithert.MonadChain(
readerio.MonadChain[R, either.Either[E, A], either.Either[E, B]],
readerio.Of[R, either.Either[E, B]],
fa,
f)
} }
func MonadChainFirst[R, E, A, B any](fa ReaderIOEither[R, E, A], f func(A) ReaderIOEither[R, E, B]) ReaderIOEither[R, E, A] { func MonadChainFirst[R, E, A, B any](fa ReaderIOEither[R, E, A], f func(A) ReaderIOEither[R, E, B]) ReaderIOEither[R, E, A] {
return G.MonadChainFirst(fa, f) return chain.MonadChainFirst(
MonadChain[R, E, A, A],
MonadMap[R, E, B, A],
fa,
f)
} }
func MonadChainEitherK[R, E, A, B any](ma ReaderIOEither[R, E, A], f func(A) ET.Either[E, B]) ReaderIOEither[R, E, B] { func MonadChainEitherK[R, E, A, B any](ma ReaderIOEither[R, E, A], f func(A) either.Either[E, B]) ReaderIOEither[R, E, B] {
return G.MonadChainEitherK[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](ma, f) return fromeither.MonadChainEitherK(
MonadChain[R, E, A, B],
FromEither[R, E, B],
ma,
f,
)
} }
func ChainEitherK[R, E, A, B any](f func(A) ET.Either[E, B]) func(ma ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] { func ChainEitherK[R, E, A, B any](f func(A) either.Either[E, B]) func(ma ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] {
return G.ChainEitherK[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](f) return fromeither.ChainEitherK(
Chain[R, E, A, B],
FromEither[R, E, B],
f,
)
} }
func MonadChainFirstEitherK[R, E, A, B any](ma ReaderIOEither[R, E, A], f func(A) ET.Either[E, B]) ReaderIOEither[R, E, A] { func MonadChainFirstEitherK[R, E, A, B any](ma ReaderIOEither[R, E, A], f func(A) either.Either[E, B]) ReaderIOEither[R, E, A] {
return G.MonadChainFirstEitherK[ReaderIOEither[R, E, A]](ma, f) return G.MonadChainFirstEitherK[ReaderIOEither[R, E, A]](ma, f)
} }
func ChainFirstEitherK[R, E, A, B any](f func(A) ET.Either[E, B]) func(ma ReaderIOEither[R, E, A]) ReaderIOEither[R, E, A] { func ChainFirstEitherK[R, E, A, B any](f func(A) either.Either[E, B]) func(ma ReaderIOEither[R, E, A]) ReaderIOEither[R, E, A] {
return G.ChainFirstEitherK[ReaderIOEither[R, E, A]](f) return G.ChainFirstEitherK[ReaderIOEither[R, E, A]](f)
} }
func MonadChainReaderK[R, E, A, B any](ma ReaderIOEither[R, E, A], f func(A) RD.Reader[R, B]) ReaderIOEither[R, E, B] { func MonadChainReaderK[R, E, A, B any](ma ReaderIOEither[R, E, A], f func(A) reader.Reader[R, B]) ReaderIOEither[R, E, B] {
return G.MonadChainReaderK[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](ma, f) return G.MonadChainReaderK[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](ma, f)
} }
func ChainReaderK[E, R, A, B any](f func(A) RD.Reader[R, B]) func(ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] { func ChainReaderK[E, R, A, B any](f func(A) reader.Reader[R, B]) func(ReaderIOEither[R, E, A]) ReaderIOEither[R, E, B] {
return G.ChainReaderK[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](f) return G.ChainReaderK[ReaderIOEither[R, E, A], ReaderIOEither[R, E, B]](f)
} }
@@ -163,20 +193,20 @@ func Flatten[R, E, A any](mma ReaderIOEither[R, E, ReaderIOEither[R, E, A]]) Rea
return G.Flatten(mma) return G.Flatten(mma)
} }
func FromEither[R, E, A any](t ET.Either[E, A]) ReaderIOEither[R, E, A] { func FromEither[R, E, A any](t either.Either[E, A]) ReaderIOEither[R, E, A] {
return G.FromEither[ReaderIOEither[R, E, A]](t) return G.FromEither[ReaderIOEither[R, E, A]](t)
} }
func RightReader[E, R, A any](ma RD.Reader[R, A]) ReaderIOEither[R, E, A] { func RightReader[E, R, A any](ma reader.Reader[R, A]) ReaderIOEither[R, E, A] {
return G.RightReader[RD.Reader[R, A], ReaderIOEither[R, E, A]](ma) return G.RightReader[reader.Reader[R, A], ReaderIOEither[R, E, A]](ma)
} }
func LeftReader[A, R, E any](ma RD.Reader[R, E]) ReaderIOEither[R, E, A] { func LeftReader[A, R, E any](ma reader.Reader[R, E]) ReaderIOEither[R, E, A] {
return G.LeftReader[RD.Reader[R, E], ReaderIOEither[R, E, A]](ma) return G.LeftReader[reader.Reader[R, E], ReaderIOEither[R, E, A]](ma)
} }
func FromReader[E, R, A any](ma RD.Reader[R, A]) ReaderIOEither[R, E, A] { func FromReader[E, R, A any](ma reader.Reader[R, A]) ReaderIOEither[R, E, A] {
return G.FromReader[RD.Reader[R, A], ReaderIOEither[R, E, A]](ma) return G.FromReader[reader.Reader[R, A], ReaderIOEither[R, E, A]](ma)
} }
func RightIO[R, E, A any](ma io.IO[A]) ReaderIOEither[R, E, A] { func RightIO[R, E, A any](ma io.IO[A]) ReaderIOEither[R, E, A] {
@@ -203,8 +233,8 @@ func Ask[R, E any]() ReaderIOEither[R, E, R] {
return G.Ask[ReaderIOEither[R, E, R]]() return G.Ask[ReaderIOEither[R, E, R]]()
} }
func Asks[E, R, A any](r RD.Reader[R, A]) ReaderIOEither[R, E, A] { func Asks[E, R, A any](r reader.Reader[R, A]) ReaderIOEither[R, E, A] {
return G.Asks[RD.Reader[R, A], ReaderIOEither[R, E, A]](r) return G.Asks[reader.Reader[R, A], ReaderIOEither[R, E, A]](r)
} }
func FromOption[R, A, E any](onNone func() E) func(O.Option[A]) ReaderIOEither[R, E, A] { func FromOption[R, A, E any](onNone func() E) func(O.Option[A]) ReaderIOEither[R, E, A] {
@@ -215,20 +245,20 @@ func FromPredicate[R, E, A any](pred func(A) bool, onFalse func(A) E) func(A) Re
return G.FromPredicate[ReaderIOEither[R, E, A]](pred, onFalse) return G.FromPredicate[ReaderIOEither[R, E, A]](pred, onFalse)
} }
func Fold[R, E, A, B any](onLeft func(E) RIO.ReaderIO[R, B], onRight func(A) RIO.ReaderIO[R, B]) func(ReaderIOEither[R, E, A]) RIO.ReaderIO[R, B] { func Fold[R, E, A, B any](onLeft func(E) readerio.ReaderIO[R, B], onRight func(A) readerio.ReaderIO[R, B]) func(ReaderIOEither[R, E, A]) readerio.ReaderIO[R, B] {
return G.Fold[RIO.ReaderIO[R, B], ReaderIOEither[R, E, A]](onLeft, onRight) return G.Fold[readerio.ReaderIO[R, B], ReaderIOEither[R, E, A]](onLeft, onRight)
} }
func GetOrElse[R, E, A any](onLeft func(E) RIO.ReaderIO[R, A]) func(ReaderIOEither[R, E, A]) RIO.ReaderIO[R, A] { func GetOrElse[R, E, A any](onLeft func(E) readerio.ReaderIO[R, A]) func(ReaderIOEither[R, E, A]) readerio.ReaderIO[R, A] {
return G.GetOrElse[RIO.ReaderIO[R, A], ReaderIOEither[R, E, A]](onLeft) return G.GetOrElse[readerio.ReaderIO[R, A], ReaderIOEither[R, E, A]](onLeft)
} }
func OrElse[R, E1, A, E2 any](onLeft func(E1) ReaderIOEither[R, E2, A]) func(ReaderIOEither[R, E1, A]) ReaderIOEither[R, E2, A] { func OrElse[R, E1, A, E2 any](onLeft func(E1) ReaderIOEither[R, E2, A]) func(ReaderIOEither[R, E1, A]) ReaderIOEither[R, E2, A] {
return G.OrElse[ReaderIOEither[R, E1, A]](onLeft) return G.OrElse[ReaderIOEither[R, E1, A]](onLeft)
} }
func OrLeft[A, E1, R, E2 any](onLeft func(E1) RIO.ReaderIO[R, E2]) func(ReaderIOEither[R, E1, A]) ReaderIOEither[R, E2, A] { func OrLeft[A, E1, R, E2 any](onLeft func(E1) readerio.ReaderIO[R, E2]) func(ReaderIOEither[R, E1, A]) ReaderIOEither[R, E2, A] {
return G.OrLeft[ReaderIOEither[R, E1, A], RIO.ReaderIO[R, E2], ReaderIOEither[R, E2, A]](onLeft) return G.OrLeft[ReaderIOEither[R, E1, A], readerio.ReaderIO[R, E2], ReaderIOEither[R, E2, A]](onLeft)
} }
func MonadBiMap[R, E1, E2, A, B any](fa ReaderIOEither[R, E1, A], f func(E1) E2, g func(A) B) ReaderIOEither[R, E2, B] { func MonadBiMap[R, E1, E2, A, B any](fa ReaderIOEither[R, E1, A], f func(E1) E2, g func(A) B) ReaderIOEither[R, E2, B] {

View File

@@ -24,7 +24,7 @@ import (
F "github.com/IBM/fp-go/v2/function" F "github.com/IBM/fp-go/v2/function"
"github.com/IBM/fp-go/v2/internal/utils" "github.com/IBM/fp-go/v2/internal/utils"
R "github.com/IBM/fp-go/v2/reader" R "github.com/IBM/fp-go/v2/reader"
RIO "github.com/IBM/fp-go/v2/readerio" "github.com/IBM/fp-go/v2/readerio"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@@ -39,8 +39,8 @@ func TestMap(t *testing.T) {
} }
func TestOrLeft(t *testing.T) { func TestOrLeft(t *testing.T) {
f := OrLeft[int](func(s string) RIO.ReaderIO[context.Context, string] { f := OrLeft[int](func(s string) readerio.ReaderIO[context.Context, string] {
return RIO.Of[context.Context](s + "!") return readerio.Of[context.Context](s + "!")
}) })
g1 := F.Pipe1( g1 := F.Pipe1(

View File

@@ -15,11 +15,21 @@
package readerioeither package readerioeither
import ( import "github.com/IBM/fp-go/v2/ioeither"
G "github.com/IBM/fp-go/v2/readerioeither/generic"
)
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource // WithResource constructs a function that creates a resource, then operates on it and then releases the resource
func WithResource[A, L, E, R any](onCreate ReaderIOEither[L, E, R], onRelease func(R) ReaderIOEither[L, E, any]) func(func(R) ReaderIOEither[L, E, A]) ReaderIOEither[L, E, A] { func WithResource[A, L, E, R, ANY any](onCreate ReaderIOEither[L, E, R], onRelease func(R) ReaderIOEither[L, E, ANY]) func(func(R) ReaderIOEither[L, E, A]) ReaderIOEither[L, E, A] {
return G.WithResource[ReaderIOEither[L, E, A]](onCreate, onRelease) return func(f func(R) ReaderIOEither[L, E, A]) ReaderIOEither[L, E, A] {
return func(l L) ioeither.IOEither[E, A] {
// dispatch to the generic implementation
return ioeither.WithResource[A](
onCreate(l),
func(r R) ioeither.IOEither[E, ANY] {
return onRelease(r)(l)
},
)(func(r R) ioeither.IOEither[E, A] {
return f(r)(l)
})
}
}
} }

View File

@@ -19,7 +19,7 @@ import (
"context" "context"
"testing" "testing"
ET "github.com/IBM/fp-go/v2/either" "github.com/IBM/fp-go/v2/either"
T "github.com/IBM/fp-go/v2/tuple" T "github.com/IBM/fp-go/v2/tuple"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@@ -34,5 +34,5 @@ func TestSequence2(t *testing.T) {
res := s2(first, second) res := s2(first, second)
ctx := context.Background() ctx := context.Background()
assert.Equal(t, ET.Right[error](T.MakeTuple2("a", 1)), res(ctx)()) assert.Equal(t, either.Right[error](T.MakeTuple2("a", 1)), res(ctx)())
} }