mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-26 19:38:58 +02:00
Compare commits
25 Commits
v1.0.33
...
cleue-add-
Author | SHA1 | Date | |
---|---|---|---|
|
1eefc28ba6 | ||
|
af2915d98a | ||
|
e9f9c2777f | ||
|
895862a67e | ||
|
caf0574742 | ||
|
bace6f01eb | ||
|
254c63a16f | ||
|
655c8a9b1d | ||
|
c6d6be66e0 | ||
|
e313f95865 | ||
|
5f25317f97 | ||
|
f5aa2d6c15 | ||
|
7262820624 | ||
|
c8fc10358b | ||
|
1cd167541d | ||
|
ebe94d71dc | ||
|
7ef6eb524b | ||
|
7b82e87bf3 | ||
|
e8fdbe9f87 | ||
|
226c7039de | ||
|
943ae8e009 | ||
|
44c8441b07 | ||
|
600aeae770 | ||
|
f74a407294 | ||
|
b15ab38861 |
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -29,7 +29,7 @@ jobs:
|
||||
go-version: [ '1.20.x', '1.21.x' ]
|
||||
steps:
|
||||
# full checkout for semantic-release
|
||||
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
||||
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up go ${{ matrix.go-version }}
|
||||
@@ -55,7 +55,7 @@ jobs:
|
||||
steps:
|
||||
# full checkout for semantic-release
|
||||
- name: Full checkout
|
||||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
||||
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
@@ -308,3 +308,11 @@ func Fold[A any](m M.Monoid[A]) func([]A) A {
|
||||
func Push[A any](a A) func([]A) []A {
|
||||
return G.Push[[]A](a)
|
||||
}
|
||||
|
||||
func MonadFlap[B, A any](fab []func(A) B, a A) []B {
|
||||
return G.MonadFlap[func(A) B, []func(A) B, []B, A, B](fab, a)
|
||||
}
|
||||
|
||||
func Flap[B, A any](a A) func([]func(A) B) []B {
|
||||
return G.Flap[func(A) B, []func(A) B, []B, A, B](a)
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package generic
|
||||
import (
|
||||
F "github.com/IBM/fp-go/function"
|
||||
"github.com/IBM/fp-go/internal/array"
|
||||
FC "github.com/IBM/fp-go/internal/functor"
|
||||
M "github.com/IBM/fp-go/monoid"
|
||||
O "github.com/IBM/fp-go/option"
|
||||
"github.com/IBM/fp-go/tuple"
|
||||
@@ -250,3 +251,11 @@ func Fold[AS ~[]A, A any](m M.Monoid[A]) func(AS) A {
|
||||
func Push[GA ~[]A, A any](a A) func(GA) GA {
|
||||
return F.Bind2nd(array.Push[GA, A], a)
|
||||
}
|
||||
|
||||
func MonadFlap[FAB ~func(A) B, GFAB ~[]FAB, GB ~[]B, A, B any](fab GFAB, a A) GB {
|
||||
return FC.MonadFlap(MonadMap[GFAB, GB], fab, a)
|
||||
}
|
||||
|
||||
func Flap[FAB ~func(A) B, GFAB ~[]FAB, GB ~[]B, A, B any](a A) func(GFAB) GB {
|
||||
return F.Bind2nd(MonadFlap[FAB, GFAB, GB, A, B], a)
|
||||
}
|
||||
|
124
array/nonempty/array.go
Normal file
124
array/nonempty/array.go
Normal file
@@ -0,0 +1,124 @@
|
||||
// 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 nonempty
|
||||
|
||||
import (
|
||||
G "github.com/IBM/fp-go/array/generic"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
"github.com/IBM/fp-go/internal/array"
|
||||
S "github.com/IBM/fp-go/semigroup"
|
||||
)
|
||||
|
||||
// NonEmptyArray represents an array with at least one element
|
||||
type NonEmptyArray[A any] []A
|
||||
|
||||
// Of constructs a single element array
|
||||
func Of[A any](first A) NonEmptyArray[A] {
|
||||
return G.Of[NonEmptyArray[A]](first)
|
||||
}
|
||||
|
||||
// From constructs a [NonEmptyArray] from a set of variadic arguments
|
||||
func From[A any](first A, data ...A) NonEmptyArray[A] {
|
||||
count := len(data)
|
||||
if count == 0 {
|
||||
return Of(first)
|
||||
}
|
||||
// allocate the requested buffer
|
||||
buffer := make(NonEmptyArray[A], count+1)
|
||||
buffer[0] = first
|
||||
copy(buffer[1:], data)
|
||||
return buffer
|
||||
}
|
||||
|
||||
func IsEmpty[A any](as NonEmptyArray[A]) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func IsNonEmpty[A any](as NonEmptyArray[A]) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func MonadMap[A, B any](as NonEmptyArray[A], f func(a A) B) NonEmptyArray[B] {
|
||||
return G.MonadMap[NonEmptyArray[A], NonEmptyArray[B]](as, f)
|
||||
}
|
||||
|
||||
func Map[A, B any](f func(a A) B) func(NonEmptyArray[A]) NonEmptyArray[B] {
|
||||
return F.Bind2nd(MonadMap[A, B], f)
|
||||
}
|
||||
|
||||
func Reduce[A, B any](f func(B, A) B, initial B) func(NonEmptyArray[A]) B {
|
||||
return func(as NonEmptyArray[A]) B {
|
||||
return array.Reduce(as, f, initial)
|
||||
}
|
||||
}
|
||||
|
||||
func Tail[A any](as NonEmptyArray[A]) []A {
|
||||
return as[1:]
|
||||
}
|
||||
|
||||
func Head[A any](as NonEmptyArray[A]) A {
|
||||
return as[0]
|
||||
}
|
||||
|
||||
func First[A any](as NonEmptyArray[A]) A {
|
||||
return as[0]
|
||||
}
|
||||
|
||||
func Last[A any](as NonEmptyArray[A]) A {
|
||||
return as[len(as)-1]
|
||||
}
|
||||
|
||||
func Size[A any](as NonEmptyArray[A]) int {
|
||||
return G.Size(as)
|
||||
}
|
||||
|
||||
func Flatten[A any](mma NonEmptyArray[NonEmptyArray[A]]) NonEmptyArray[A] {
|
||||
return G.Flatten(mma)
|
||||
}
|
||||
|
||||
func MonadChain[A, B any](fa NonEmptyArray[A], f func(a A) NonEmptyArray[B]) NonEmptyArray[B] {
|
||||
return G.MonadChain[NonEmptyArray[A], NonEmptyArray[B]](fa, f)
|
||||
}
|
||||
|
||||
func Chain[A, B any](f func(A) NonEmptyArray[B]) func(NonEmptyArray[A]) NonEmptyArray[B] {
|
||||
return G.Chain[NonEmptyArray[A], NonEmptyArray[B]](f)
|
||||
}
|
||||
|
||||
func MonadAp[B, A any](fab NonEmptyArray[func(A) B], fa NonEmptyArray[A]) NonEmptyArray[B] {
|
||||
return G.MonadAp[NonEmptyArray[B]](fab, fa)
|
||||
}
|
||||
|
||||
func Ap[B, A any](fa NonEmptyArray[A]) func(NonEmptyArray[func(A) B]) NonEmptyArray[B] {
|
||||
return G.Ap[NonEmptyArray[B], NonEmptyArray[func(A) B]](fa)
|
||||
}
|
||||
|
||||
// FoldMap maps and folds a [NonEmptyArray]. Map the [NonEmptyArray] passing each value to the iterating function. Then fold the results using the provided [Semigroup].
|
||||
func FoldMap[A, B any](s S.Semigroup[B]) func(func(A) B) func(NonEmptyArray[A]) B {
|
||||
return func(f func(A) B) func(NonEmptyArray[A]) B {
|
||||
return func(as NonEmptyArray[A]) B {
|
||||
return array.Reduce(Tail(as), func(cur B, a A) B {
|
||||
return s.Concat(cur, f(a))
|
||||
}, f(Head(as)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fold folds the [NonEmptyArray] using the provided [Semigroup].
|
||||
func Fold[A any](s S.Semigroup[A]) func(NonEmptyArray[A]) A {
|
||||
return func(as NonEmptyArray[A]) A {
|
||||
return array.Reduce(Tail(as), s.Concat, Head(as))
|
||||
}
|
||||
}
|
@@ -18,6 +18,8 @@ package readerio
|
||||
import (
|
||||
"context"
|
||||
|
||||
IO "github.com/IBM/fp-go/io"
|
||||
L "github.com/IBM/fp-go/lazy"
|
||||
R "github.com/IBM/fp-go/readerio/generic"
|
||||
)
|
||||
|
||||
@@ -37,6 +39,22 @@ func Chain[A, B any](f func(A) ReaderIO[B]) func(ReaderIO[A]) ReaderIO[B] {
|
||||
return R.Chain[ReaderIO[A]](f)
|
||||
}
|
||||
|
||||
func MonadChainIOK[A, B any](fa ReaderIO[A], f func(A) IO.IO[B]) ReaderIO[B] {
|
||||
return R.MonadChainIOK[ReaderIO[A], ReaderIO[B]](fa, f)
|
||||
}
|
||||
|
||||
func ChainIOK[A, B any](f func(A) IO.IO[B]) func(ReaderIO[A]) ReaderIO[B] {
|
||||
return R.ChainIOK[ReaderIO[A], ReaderIO[B]](f)
|
||||
}
|
||||
|
||||
func MonadChainFirstIOK[A, B any](fa ReaderIO[A], f func(A) IO.IO[B]) ReaderIO[A] {
|
||||
return R.MonadChainFirstIOK[ReaderIO[A], ReaderIO[B]](fa, f)
|
||||
}
|
||||
|
||||
func ChainFirstIOK[A, B any](f func(A) IO.IO[B]) func(ReaderIO[A]) ReaderIO[A] {
|
||||
return R.ChainFirstIOK[ReaderIO[A], ReaderIO[B]](f)
|
||||
}
|
||||
|
||||
func Of[A any](a A) ReaderIO[A] {
|
||||
return R.Of[ReaderIO[A]](a)
|
||||
}
|
||||
@@ -54,6 +72,18 @@ func Ask() ReaderIO[context.Context] {
|
||||
}
|
||||
|
||||
// Defer creates an IO by creating a brand new IO via a generator function, each time
|
||||
func Defer[A any](gen func() ReaderIO[A]) ReaderIO[A] {
|
||||
func Defer[A any](gen L.Lazy[ReaderIO[A]]) ReaderIO[A] {
|
||||
return R.Defer[ReaderIO[A]](gen)
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided [ReaderIO] monad lazily but exactly once
|
||||
// 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
|
||||
func Memoize[A any](rdr ReaderIO[A]) ReaderIO[A] {
|
||||
return R.Memoize[ReaderIO[A]](rdr)
|
||||
}
|
||||
|
||||
// Flatten converts a nested [ReaderIO] into a [ReaderIO]
|
||||
func Flatten[A any](mma ReaderIO[ReaderIO[A]]) ReaderIO[A] {
|
||||
return R.Flatten[ReaderIO[A]](mma)
|
||||
}
|
||||
|
@@ -25,25 +25,31 @@ import (
|
||||
F "github.com/IBM/fp-go/function"
|
||||
"github.com/IBM/fp-go/internal/file"
|
||||
IOE "github.com/IBM/fp-go/ioeither"
|
||||
IOEF "github.com/IBM/fp-go/ioeither/file"
|
||||
)
|
||||
|
||||
var (
|
||||
openIOE = IOE.Eitherize1(os.Open)
|
||||
// Open opens a file for reading within the given context
|
||||
Open = F.Flow3(
|
||||
openIOE,
|
||||
IOEF.Open,
|
||||
RIOE.FromIOEither[*os.File],
|
||||
RIOE.WithContext[*os.File],
|
||||
)
|
||||
|
||||
// Remove removes a file by name
|
||||
Remove = F.Flow2(
|
||||
IOEF.Remove,
|
||||
RIOE.FromIOEither[string],
|
||||
)
|
||||
)
|
||||
|
||||
// Close closes an object
|
||||
func Close[C io.Closer](c C) RIOE.ReaderIOEither[any] {
|
||||
return RIOE.FromIOEither(func() ET.Either[error, any] {
|
||||
return ET.TryCatchError(func() (any, error) {
|
||||
return c, c.Close()
|
||||
})
|
||||
})
|
||||
return F.Pipe2(
|
||||
c,
|
||||
IOEF.Close[C],
|
||||
RIOE.FromIOEither[any],
|
||||
)
|
||||
}
|
||||
|
||||
// ReadFile reads a file in the scope of a context
|
||||
|
52
context/readerioeither/file/tempfile.go
Normal file
52
context/readerioeither/file/tempfile.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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 file
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
RIOE "github.com/IBM/fp-go/context/readerioeither"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
IO "github.com/IBM/fp-go/io"
|
||||
IOF "github.com/IBM/fp-go/io/file"
|
||||
IOEF "github.com/IBM/fp-go/ioeither/file"
|
||||
)
|
||||
|
||||
var (
|
||||
// onCreateTempFile creates a temp file with sensible defaults
|
||||
onCreateTempFile = CreateTemp("", "*")
|
||||
// destroy handler
|
||||
onReleaseTempFile = F.Flow4(
|
||||
IOF.Close[*os.File],
|
||||
IO.Map((*os.File).Name),
|
||||
RIOE.FromIO[string],
|
||||
RIOE.Chain(Remove),
|
||||
)
|
||||
)
|
||||
|
||||
// CreateTemp created a temp file with proper parametrization
|
||||
func CreateTemp(dir, pattern string) RIOE.ReaderIOEither[*os.File] {
|
||||
return F.Pipe2(
|
||||
IOEF.CreateTemp(dir, pattern),
|
||||
RIOE.FromIOEither[*os.File],
|
||||
RIOE.WithContext[*os.File],
|
||||
)
|
||||
}
|
||||
|
||||
// WithTempFile creates a temporary file, then invokes a callback to create a resource based on the file, then close and remove the temp file
|
||||
func WithTempFile[A any](f func(*os.File) RIOE.ReaderIOEither[A]) RIOE.ReaderIOEither[A] {
|
||||
return RIOE.WithResource[A](onCreateTempFile, onReleaseTempFile)(f)
|
||||
}
|
47
context/readerioeither/file/tempfile_test.go
Normal file
47
context/readerioeither/file/tempfile_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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 file
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
RIOE "github.com/IBM/fp-go/context/readerioeither"
|
||||
E "github.com/IBM/fp-go/either"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWithTempFile(t *testing.T) {
|
||||
|
||||
res := WithTempFile(onWriteAll[*os.File]([]byte("Carsten")))
|
||||
|
||||
assert.Equal(t, E.Of[error]([]byte("Carsten")), res(context.Background())())
|
||||
}
|
||||
|
||||
func TestWithTempFileOnClosedFile(t *testing.T) {
|
||||
|
||||
res := WithTempFile(func(f *os.File) RIOE.ReaderIOEither[[]byte] {
|
||||
return F.Pipe2(
|
||||
f,
|
||||
onWriteAll[*os.File]([]byte("Carsten")),
|
||||
RIOE.ChainFirst(F.Constant1[[]byte](Close(f))),
|
||||
)
|
||||
})
|
||||
|
||||
assert.Equal(t, E.Of[error]([]byte("Carsten")), res(context.Background())())
|
||||
}
|
57
context/readerioeither/file/write.go
Normal file
57
context/readerioeither/file/write.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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 file
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
RIOE "github.com/IBM/fp-go/context/readerioeither"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
)
|
||||
|
||||
func onWriteAll[W io.Writer](data []byte) func(w W) RIOE.ReaderIOEither[[]byte] {
|
||||
return func(w W) RIOE.ReaderIOEither[[]byte] {
|
||||
return F.Pipe1(
|
||||
RIOE.TryCatch(func(ctx context.Context) func() ([]byte, error) {
|
||||
return func() ([]byte, error) {
|
||||
_, err := w.Write(data)
|
||||
return data, err
|
||||
}
|
||||
}),
|
||||
RIOE.WithContext[[]byte],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// WriteAll uses a generator function to create a stream, writes data to it and closes it
|
||||
func WriteAll[W io.WriteCloser](data []byte) func(acquire RIOE.ReaderIOEither[W]) RIOE.ReaderIOEither[[]byte] {
|
||||
onWrite := onWriteAll[W](data)
|
||||
return func(onCreate RIOE.ReaderIOEither[W]) RIOE.ReaderIOEither[[]byte] {
|
||||
return RIOE.WithResource[[]byte](
|
||||
onCreate,
|
||||
Close[W])(
|
||||
onWrite,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Write uses a generator function to create a stream, writes data to it and closes it
|
||||
func Write[R any, W io.WriteCloser](acquire RIOE.ReaderIOEither[W]) func(use func(W) RIOE.ReaderIOEither[R]) RIOE.ReaderIOEither[R] {
|
||||
return RIOE.WithResource[R](
|
||||
acquire,
|
||||
Close[W])
|
||||
}
|
@@ -100,6 +100,28 @@ func Map[
|
||||
return RIE.Map[GRA, GRB](f)
|
||||
}
|
||||
|
||||
func MonadMapTo[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
|
||||
A, B any](fa GRA, b B) GRB {
|
||||
return RIE.MonadMapTo[GRA, GRB](fa, b)
|
||||
}
|
||||
|
||||
func MapTo[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
|
||||
A, B any](b B) func(GRA) GRB {
|
||||
return RIE.MapTo[GRA, GRB](b)
|
||||
}
|
||||
|
||||
func MonadChain[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
@@ -458,6 +480,34 @@ func ChainIOK[
|
||||
return RIE.ChainIOK[GRA, GRB](f)
|
||||
}
|
||||
|
||||
func MonadChainReaderIOK[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRIO ~func(context.Context) GIO,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
|
||||
GIO ~func() B,
|
||||
|
||||
A, B any](ma GRA, f func(A) GRIO) GRB {
|
||||
return RIE.MonadChainReaderIOK[GRA, GRB](ma, f)
|
||||
}
|
||||
|
||||
func ChainReaderIOK[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRIO ~func(context.Context) GIO,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
|
||||
GIO ~func() B,
|
||||
|
||||
A, B any](f func(A) GRIO) func(ma GRA) GRB {
|
||||
return RIE.ChainReaderIOK[GRA, GRB](f)
|
||||
}
|
||||
|
||||
func MonadChainFirstIOK[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
@@ -551,3 +601,66 @@ func MonadAlt[LAZY ~func() GEA, GEA ~func(context.Context) GIOA, GIOA ~func() E.
|
||||
func Alt[LAZY ~func() GEA, GEA ~func(context.Context) GIOA, GIOA ~func() E.Either[error, A], A any](second LAZY) func(GEA) GEA {
|
||||
return RIE.Alt(second)
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided monad lazily but exactly once
|
||||
// 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
|
||||
func Memoize[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](rdr GRA) GRA {
|
||||
return RIE.Memoize[GRA](rdr)
|
||||
}
|
||||
|
||||
func Flatten[
|
||||
GGRA ~func(context.Context) GGIOA,
|
||||
GGIOA ~func() E.Either[error, GRA],
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](rdr GGRA) GRA {
|
||||
return RIE.Flatten[GRA](rdr)
|
||||
}
|
||||
|
||||
func MonadFromReaderIO[
|
||||
GRIOEA ~func(context.Context) GIOEA,
|
||||
GIOEA ~func() E.Either[error, A],
|
||||
|
||||
GRIOA ~func(context.Context) GIOA,
|
||||
GIOA ~func() A,
|
||||
|
||||
A any](a A, f func(A) GRIOA) GRIOEA {
|
||||
return RIE.MonadFromReaderIO[GRIOEA](a, f)
|
||||
}
|
||||
|
||||
func FromReaderIO[
|
||||
GRIOEA ~func(context.Context) GIOEA,
|
||||
GIOEA ~func() E.Either[error, A],
|
||||
|
||||
GRIOA ~func(context.Context) GIOA,
|
||||
GIOA ~func() A,
|
||||
|
||||
A any](f func(A) GRIOA) func(A) GRIOEA {
|
||||
return RIE.FromReaderIO[GRIOEA](f)
|
||||
}
|
||||
|
||||
func RightReaderIO[
|
||||
GRIOEA ~func(context.Context) GIOEA,
|
||||
GIOEA ~func() E.Either[error, A],
|
||||
|
||||
GRIOA ~func(context.Context) GIOA,
|
||||
GIOA ~func() A,
|
||||
|
||||
A any](ma GRIOA) GRIOEA {
|
||||
return RIE.RightReaderIO[GRIOEA](ma)
|
||||
}
|
||||
|
||||
func LeftReaderIO[
|
||||
GRIOEA ~func(context.Context) GIOEA,
|
||||
GIOEA ~func() E.Either[error, A],
|
||||
|
||||
GRIOE ~func(context.Context) GIOE,
|
||||
GIOE ~func() error,
|
||||
|
||||
A any](ma GRIOE) GRIOEA {
|
||||
return RIE.LeftReaderIO[GRIOEA](ma)
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package readerioeither
|
||||
|
||||
import (
|
||||
G "github.com/IBM/fp-go/context/readerioeither/generic"
|
||||
L "github.com/IBM/fp-go/lazy"
|
||||
M "github.com/IBM/fp-go/monoid"
|
||||
)
|
||||
|
||||
@@ -34,3 +35,22 @@ func ApplicativeMonoidSeq[A any](m M.Monoid[A]) M.Monoid[ReaderIOEither[A]] {
|
||||
func ApplicativeMonoidPar[A any](m M.Monoid[A]) M.Monoid[ReaderIOEither[A]] {
|
||||
return G.ApplicativeMonoidPar[ReaderIOEither[A], ReaderIOEither[func(A) A]](m)
|
||||
}
|
||||
|
||||
// AlternativeMonoid is the alternative [Monoid] for [ReaderIOEither]
|
||||
func AlternativeMonoid[A any](m M.Monoid[A]) M.Monoid[ReaderIOEither[A]] {
|
||||
return M.AlternativeMonoid(
|
||||
Of[A],
|
||||
MonadMap[A, func(A) A],
|
||||
MonadAp[A, A],
|
||||
MonadAlt[A],
|
||||
m,
|
||||
)
|
||||
}
|
||||
|
||||
// AltMonoid is the alternative [Monoid] for an [ReaderIOEither]
|
||||
func AltMonoid[A any](zero L.Lazy[ReaderIOEither[A]]) M.Monoid[ReaderIOEither[A]] {
|
||||
return M.AltMonoid(
|
||||
zero,
|
||||
MonadAlt[A],
|
||||
)
|
||||
}
|
||||
|
@@ -61,6 +61,14 @@ func Map[A, B any](f func(A) B) func(ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return G.Map[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
}
|
||||
|
||||
func MonadMapTo[A, B any](fa ReaderIOEither[A], b B) ReaderIOEither[B] {
|
||||
return G.MonadMapTo[ReaderIOEither[A], ReaderIOEither[B]](fa, b)
|
||||
}
|
||||
|
||||
func MapTo[A, B any](b B) func(ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return G.MapTo[ReaderIOEither[A], ReaderIOEither[B]](b)
|
||||
}
|
||||
|
||||
func MonadChain[A, B any](ma ReaderIOEither[A], f func(A) ReaderIOEither[B]) ReaderIOEither[B] {
|
||||
return G.MonadChain(ma, f)
|
||||
}
|
||||
@@ -147,11 +155,23 @@ func FromIO[A any](t IO.IO[A]) ReaderIOEither[A] {
|
||||
return G.FromIO[ReaderIOEither[A]](t)
|
||||
}
|
||||
|
||||
func FromLazy[A any](t L.Lazy[A]) ReaderIOEither[A] {
|
||||
return G.FromIO[ReaderIOEither[A]](t)
|
||||
}
|
||||
|
||||
// Never returns a 'ReaderIOEither' that never returns, except if its context gets canceled
|
||||
func Never[A any]() ReaderIOEither[A] {
|
||||
return G.Never[ReaderIOEither[A]]()
|
||||
}
|
||||
|
||||
func MonadChainReaderIOK[A, B any](ma ReaderIOEither[A], f func(A) RIO.ReaderIO[B]) ReaderIOEither[B] {
|
||||
return G.MonadChainReaderIOK[ReaderIOEither[B], ReaderIOEither[A]](ma, f)
|
||||
}
|
||||
|
||||
func ChainReaderIOK[A, B any](f func(A) RIO.ReaderIO[B]) func(ma ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return G.ChainReaderIOK[ReaderIOEither[B], ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func MonadChainIOK[A, B any](ma ReaderIOEither[A], f func(A) IO.IO[B]) ReaderIOEither[B] {
|
||||
return G.MonadChainIOK[ReaderIOEither[B], ReaderIOEither[A]](ma, f)
|
||||
}
|
||||
@@ -201,3 +221,32 @@ func MonadAlt[A any](first ReaderIOEither[A], second L.Lazy[ReaderIOEither[A]])
|
||||
func Alt[A any](second L.Lazy[ReaderIOEither[A]]) func(ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return G.Alt(second)
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided [ReaderIOEither] monad lazily but exactly once
|
||||
// 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
|
||||
func Memoize[A any](rdr ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return G.Memoize[ReaderIOEither[A]](rdr)
|
||||
}
|
||||
|
||||
// Flatten converts a nested [ReaderIOEither] into a [ReaderIOEither]
|
||||
func Flatten[
|
||||
A any](rdr ReaderIOEither[ReaderIOEither[A]]) ReaderIOEither[A] {
|
||||
return G.Flatten[ReaderIOEither[ReaderIOEither[A]]](rdr)
|
||||
}
|
||||
|
||||
func MonadFromReaderIO[A any](a A, f func(A) RIO.ReaderIO[A]) ReaderIOEither[A] {
|
||||
return G.MonadFromReaderIO[ReaderIOEither[A]](a, f)
|
||||
}
|
||||
|
||||
func FromReaderIO[A any](f func(A) RIO.ReaderIO[A]) func(A) ReaderIOEither[A] {
|
||||
return G.FromReaderIO[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func RightReaderIO[A any](ma RIO.ReaderIO[A]) ReaderIOEither[A] {
|
||||
return G.RightReaderIO[ReaderIOEither[A]](ma)
|
||||
}
|
||||
|
||||
func LeftReaderIO[A any](ma RIO.ReaderIO[error]) ReaderIOEither[A] {
|
||||
return G.LeftReaderIO[ReaderIOEither[A]](ma)
|
||||
}
|
||||
|
@@ -162,3 +162,125 @@ func TestRegularApply(t *testing.T) {
|
||||
res := applied(context.Background())()
|
||||
assert.Equal(t, E.Of[error]("CARSTEN"), res)
|
||||
}
|
||||
|
||||
func TestWithResourceNoErrors(t *testing.T) {
|
||||
var countAcquire, countBody, countRelease int
|
||||
|
||||
acquire := FromLazy(func() int {
|
||||
countAcquire++
|
||||
return countAcquire
|
||||
})
|
||||
|
||||
release := func(int) ReaderIOEither[int] {
|
||||
return FromLazy(func() int {
|
||||
countRelease++
|
||||
return countRelease
|
||||
})
|
||||
}
|
||||
|
||||
body := func(int) ReaderIOEither[int] {
|
||||
return FromLazy(func() int {
|
||||
countBody++
|
||||
return countBody
|
||||
})
|
||||
}
|
||||
|
||||
resRIOE := WithResource[int](acquire, release)(body)
|
||||
|
||||
res := resRIOE(context.Background())()
|
||||
|
||||
assert.Equal(t, 1, countAcquire)
|
||||
assert.Equal(t, 1, countBody)
|
||||
assert.Equal(t, 1, countRelease)
|
||||
assert.Equal(t, E.Of[error](1), res)
|
||||
}
|
||||
|
||||
func TestWithResourceErrorInBody(t *testing.T) {
|
||||
var countAcquire, countBody, countRelease int
|
||||
|
||||
acquire := FromLazy(func() int {
|
||||
countAcquire++
|
||||
return countAcquire
|
||||
})
|
||||
|
||||
release := func(int) ReaderIOEither[int] {
|
||||
return FromLazy(func() int {
|
||||
countRelease++
|
||||
return countRelease
|
||||
})
|
||||
}
|
||||
|
||||
err := fmt.Errorf("error in body")
|
||||
body := func(int) ReaderIOEither[int] {
|
||||
return Left[int](err)
|
||||
}
|
||||
|
||||
resRIOE := WithResource[int](acquire, release)(body)
|
||||
|
||||
res := resRIOE(context.Background())()
|
||||
|
||||
assert.Equal(t, 1, countAcquire)
|
||||
assert.Equal(t, 0, countBody)
|
||||
assert.Equal(t, 1, countRelease)
|
||||
assert.Equal(t, E.Left[int](err), res)
|
||||
}
|
||||
|
||||
func TestWithResourceErrorInAcquire(t *testing.T) {
|
||||
var countAcquire, countBody, countRelease int
|
||||
|
||||
err := fmt.Errorf("error in acquire")
|
||||
acquire := Left[int](err)
|
||||
|
||||
release := func(int) ReaderIOEither[int] {
|
||||
return FromLazy(func() int {
|
||||
countRelease++
|
||||
return countRelease
|
||||
})
|
||||
}
|
||||
|
||||
body := func(int) ReaderIOEither[int] {
|
||||
return FromLazy(func() int {
|
||||
countBody++
|
||||
return countBody
|
||||
})
|
||||
}
|
||||
|
||||
resRIOE := WithResource[int](acquire, release)(body)
|
||||
|
||||
res := resRIOE(context.Background())()
|
||||
|
||||
assert.Equal(t, 0, countAcquire)
|
||||
assert.Equal(t, 0, countBody)
|
||||
assert.Equal(t, 0, countRelease)
|
||||
assert.Equal(t, E.Left[int](err), res)
|
||||
}
|
||||
|
||||
func TestWithResourceErrorInRelease(t *testing.T) {
|
||||
var countAcquire, countBody, countRelease int
|
||||
|
||||
acquire := FromLazy(func() int {
|
||||
countAcquire++
|
||||
return countAcquire
|
||||
})
|
||||
|
||||
err := fmt.Errorf("error in release")
|
||||
release := func(int) ReaderIOEither[int] {
|
||||
return Left[int](err)
|
||||
}
|
||||
|
||||
body := func(int) ReaderIOEither[int] {
|
||||
return FromLazy(func() int {
|
||||
countBody++
|
||||
return countBody
|
||||
})
|
||||
}
|
||||
|
||||
resRIOE := WithResource[int](acquire, release)(body)
|
||||
|
||||
res := resRIOE(context.Background())()
|
||||
|
||||
assert.Equal(t, 1, countAcquire)
|
||||
assert.Equal(t, 1, countBody)
|
||||
assert.Equal(t, 0, countRelease)
|
||||
assert.Equal(t, E.Left[int](err), res)
|
||||
}
|
||||
|
@@ -22,6 +22,8 @@ package either
|
||||
import (
|
||||
E "github.com/IBM/fp-go/errors"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
FC "github.com/IBM/fp-go/internal/functor"
|
||||
L "github.com/IBM/fp-go/lazy"
|
||||
O "github.com/IBM/fp-go/option"
|
||||
)
|
||||
|
||||
@@ -92,11 +94,11 @@ func MonadChainTo[E, A, B any](ma Either[E, A], mb Either[E, B]) Either[E, B] {
|
||||
}
|
||||
|
||||
func MonadChainOptionK[A, B, E any](onNone func() E, ma Either[E, A], f func(A) O.Option[B]) Either[E, B] {
|
||||
return MonadChain(ma, F.Flow2(f, FromOption[E, B](onNone)))
|
||||
return MonadChain(ma, F.Flow2(f, FromOption[B](onNone)))
|
||||
}
|
||||
|
||||
func ChainOptionK[A, B, E any](onNone func() E) func(func(A) O.Option[B]) func(Either[E, A]) Either[E, B] {
|
||||
from := FromOption[E, B](onNone)
|
||||
from := FromOption[B](onNone)
|
||||
return func(f func(A) O.Option[B]) func(Either[E, A]) Either[E, B] {
|
||||
return Chain(F.Flow2(f, from))
|
||||
}
|
||||
@@ -142,7 +144,7 @@ func Sequence3[E, T1, T2, T3, R any](f func(T1, T2, T3) Either[E, R]) func(Eithe
|
||||
}
|
||||
}
|
||||
|
||||
func FromOption[E, A any](onNone func() E) func(O.Option[A]) Either[E, A] {
|
||||
func FromOption[A, E any](onNone func() E) func(O.Option[A]) Either[E, A] {
|
||||
return O.Fold(F.Nullary2(onNone, Left[A, E]), Right[E, A])
|
||||
}
|
||||
|
||||
@@ -197,11 +199,11 @@ func Reduce[E, A, B any](f func(B, A) B, initial B) func(Either[E, A]) B {
|
||||
)
|
||||
}
|
||||
|
||||
func AltW[E, E1, A any](that func() Either[E1, A]) func(Either[E, A]) Either[E1, A] {
|
||||
func AltW[E, E1, A any](that L.Lazy[Either[E1, A]]) func(Either[E, A]) Either[E1, A] {
|
||||
return Fold(F.Ignore1of1[E](that), Right[E1, A])
|
||||
}
|
||||
|
||||
func Alt[E, A any](that func() Either[E, A]) func(Either[E, A]) Either[E, A] {
|
||||
func Alt[E, A any](that L.Lazy[Either[E, A]]) func(Either[E, A]) Either[E, A] {
|
||||
return AltW[E](that)
|
||||
}
|
||||
|
||||
@@ -245,3 +247,15 @@ func MonadSequence3[E, T1, T2, T3, R any](e1 Either[E, T1], e2 Either[E, T2], e3
|
||||
func Swap[E, A any](val Either[E, A]) Either[A, E] {
|
||||
return MonadFold(val, Right[A, E], Left[E, A])
|
||||
}
|
||||
|
||||
func MonadFlap[E, B, A any](fab Either[E, func(A) B], a A) Either[E, B] {
|
||||
return FC.MonadFlap(MonadMap[E, func(A) B, B], fab, a)
|
||||
}
|
||||
|
||||
func Flap[E, B, A any](a A) func(Either[E, func(A) B]) Either[E, B] {
|
||||
return F.Bind2nd(MonadFlap[E, B, A], a)
|
||||
}
|
||||
|
||||
func MonadAlt[E, A any](fa Either[E, A], that L.Lazy[Either[E, A]]) Either[E, A] {
|
||||
return MonadFold(fa, F.Ignore1of1[E](that), Of[E, A])
|
||||
}
|
||||
|
@@ -112,6 +112,6 @@ func TestChainOptionK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFromOption(t *testing.T) {
|
||||
assert.Equal(t, Left[int]("none"), FromOption[string, int](F.Constant("none"))(O.None[int]()))
|
||||
assert.Equal(t, Right[string](1), FromOption[string, int](F.Constant("none"))(O.Some(1)))
|
||||
assert.Equal(t, Left[int]("none"), FromOption[int](F.Constant("none"))(O.None[int]()))
|
||||
assert.Equal(t, Right[string](1), FromOption[int](F.Constant("none"))(O.Some(1)))
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import (
|
||||
var (
|
||||
// Command executes a command
|
||||
// use this version if the command does not produce any side effect, i.e. if the output is uniquely determined by by the input
|
||||
// typically you'd rather use the IOEither version of the command
|
||||
// typically you'd rather use the [IOEither] version of the command
|
||||
Command = F.Curry3(command)
|
||||
)
|
||||
|
||||
|
40
either/monoid.go
Normal file
40
either/monoid.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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 either
|
||||
|
||||
import (
|
||||
L "github.com/IBM/fp-go/lazy"
|
||||
M "github.com/IBM/fp-go/monoid"
|
||||
)
|
||||
|
||||
// AlternativeMonoid is the alternative [Monoid] for an [Either]
|
||||
func AlternativeMonoid[E, A any](m M.Monoid[A]) M.Monoid[Either[E, A]] {
|
||||
return M.AlternativeMonoid(
|
||||
Of[E, A],
|
||||
MonadMap[E, A, func(A) A],
|
||||
MonadAp[A, E, A],
|
||||
MonadAlt[E, A],
|
||||
m,
|
||||
)
|
||||
}
|
||||
|
||||
// AltMonoid is the alternative [Monoid] for an [Either]
|
||||
func AltMonoid[E, A any](zero L.Lazy[Either[E, A]]) M.Monoid[Either[E, A]] {
|
||||
return M.AltMonoid(
|
||||
zero,
|
||||
MonadAlt[E, A],
|
||||
)
|
||||
}
|
@@ -13,17 +13,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package file
|
||||
package either
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
IOE "github.com/IBM/fp-go/ioeither"
|
||||
S "github.com/IBM/fp-go/semigroup"
|
||||
)
|
||||
|
||||
// onClose closes a closeable resource
|
||||
func onClose[R io.Closer](r R) IOE.IOEither[error, R] {
|
||||
return IOE.TryCatchError(func() (R, error) {
|
||||
return r, r.Close()
|
||||
})
|
||||
// AltSemigroup is the alternative [Semigroup] for an [Either]
|
||||
func AltSemigroup[E, A any]() S.Semigroup[Either[E, A]] {
|
||||
return S.AltSemigroup(
|
||||
MonadAlt[E, A],
|
||||
)
|
||||
}
|
@@ -20,11 +20,14 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// command output
|
||||
// CommandOutput represents the output of executing a command. The first field in the [Tuple2] is
|
||||
// stdout, the second one is stderr. Use [StdOut] and [StdErr] to access these fields
|
||||
CommandOutput = T.Tuple2[[]byte, []byte]
|
||||
)
|
||||
|
||||
var (
|
||||
// StdOut returns the field of a [CommandOutput] representing `stdout`
|
||||
StdOut = T.First[[]byte, []byte]
|
||||
// StdErr returns the field of a [CommandOutput] representing `stderr`
|
||||
StdErr = T.Second[[]byte, []byte]
|
||||
)
|
||||
|
@@ -15,9 +15,11 @@
|
||||
|
||||
package file
|
||||
|
||||
import "os"
|
||||
import "path/filepath"
|
||||
|
||||
// GetName is the getter for the `Name` property of [os.File]
|
||||
func GetName(f *os.File) string {
|
||||
return f.Name()
|
||||
// Join appends a filename to a root path
|
||||
func Join(name string) func(root string) string {
|
||||
return func(root string) string {
|
||||
return filepath.Join(root, name)
|
||||
}
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ var (
|
||||
GetHeader,
|
||||
R.Lookup[H.Header](HeaderContentType),
|
||||
O.Chain(A.First[string]),
|
||||
E.FromOption[error, string](errors.OnNone("unable to access the [%s] header", HeaderContentType)),
|
||||
E.FromOption[string](errors.OnNone("unable to access the [%s] header", HeaderContentType)),
|
||||
E.ChainFirst(validateJsonContentTypeString),
|
||||
)))
|
||||
)
|
||||
|
@@ -18,6 +18,7 @@ package generic
|
||||
import (
|
||||
F "github.com/IBM/fp-go/function"
|
||||
C "github.com/IBM/fp-go/internal/chain"
|
||||
FC "github.com/IBM/fp-go/internal/functor"
|
||||
)
|
||||
|
||||
func MonadAp[GAB ~func(A) B, B, A any](fab GAB, fa A) B {
|
||||
@@ -51,3 +52,11 @@ func MonadChainFirst[GAB ~func(A) B, A, B any](fa A, f GAB) A {
|
||||
func ChainFirst[GAB ~func(A) B, A, B any](f GAB) func(A) A {
|
||||
return C.ChainFirst(MonadChain[func(A) A, A, A], MonadMap[func(B) A, B, A], f)
|
||||
}
|
||||
|
||||
func MonadFlap[GAB ~func(A) B, A, B any](fab GAB, a A) B {
|
||||
return FC.MonadFlap(MonadMap[func(GAB) B, GAB, B], fab, a)
|
||||
}
|
||||
|
||||
func Flap[GAB ~func(A) B, A, B any](a A) func(GAB) B {
|
||||
return F.Bind2nd(MonadFlap[GAB, A, B], a)
|
||||
}
|
||||
|
@@ -63,3 +63,11 @@ func MonadChainFirst[A, B any](fa A, f func(A) B) A {
|
||||
func ChainFirst[A, B any](f func(A) B) func(A) A {
|
||||
return G.ChainFirst(f)
|
||||
}
|
||||
|
||||
func MonadFlap[B, A any](fab func(A) B, a A) B {
|
||||
return G.MonadFlap[func(A) B](fab, a)
|
||||
}
|
||||
|
||||
func Flap[B, A any](a A) func(func(A) B) B {
|
||||
return G.Flap[func(A) B](a)
|
||||
}
|
||||
|
@@ -22,8 +22,8 @@ import (
|
||||
O "github.com/IBM/fp-go/option"
|
||||
)
|
||||
|
||||
func FromOption[E, A, HKTEA any](fromEither func(ET.Either[E, A]) HKTEA, onNone func() E) func(ma O.Option[A]) HKTEA {
|
||||
return F.Flow2(ET.FromOption[E, A](onNone), fromEither)
|
||||
func FromOption[A, HKTEA, E any](fromEither func(ET.Either[E, A]) HKTEA, onNone func() E) func(ma O.Option[A]) HKTEA {
|
||||
return F.Flow2(ET.FromOption[A](onNone), fromEither)
|
||||
}
|
||||
|
||||
func FromPredicate[E, A, HKTEA any](fromEither func(ET.Either[E, A]) HKTEA, pred func(A) bool, onFalse func(A) E) func(A) HKTEA {
|
||||
@@ -45,7 +45,7 @@ func MonadFromOption[E, A, HKTEA any](
|
||||
)
|
||||
}
|
||||
|
||||
func FromOptionK[E, A, B, HKTEB any](
|
||||
func FromOptionK[A, E, B, HKTEB any](
|
||||
fromEither func(ET.Either[E, B]) HKTEB,
|
||||
onNone func() E) func(f func(A) O.Option[B]) func(A) HKTEB {
|
||||
// helper
|
||||
@@ -65,7 +65,7 @@ func ChainOptionK[A, E, B, HKTEA, HKTEB any](
|
||||
fromEither func(ET.Either[E, B]) HKTEB,
|
||||
onNone func() E,
|
||||
) func(f func(A) O.Option[B]) func(ma HKTEA) HKTEB {
|
||||
return F.Flow2(FromOptionK[E, A](fromEither, onNone), F.Bind1st(F.Bind2nd[HKTEA, func(A) HKTEB, HKTEB], mchain))
|
||||
return F.Flow2(FromOptionK[A](fromEither, onNone), F.Bind1st(F.Bind2nd[HKTEA, func(A) HKTEB, HKTEB], mchain))
|
||||
}
|
||||
|
||||
func MonadChainFirstEitherK[A, E, B, HKTEA, HKTEB any](
|
||||
|
37
internal/functor/flap.go
Normal file
37
internal/functor/flap.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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 functor
|
||||
|
||||
func MonadFlap[FAB ~func(A) B, A, B, HKTFAB, HKTB any](
|
||||
fmap func(HKTFAB, func(FAB) B) HKTB,
|
||||
|
||||
fab HKTFAB,
|
||||
a A,
|
||||
) HKTB {
|
||||
return fmap(fab, func(f FAB) B {
|
||||
return f(a)
|
||||
})
|
||||
}
|
||||
|
||||
func Flap[FAB ~func(A) B, A, B, HKTFAB, HKTB any](
|
||||
fmap func(HKTFAB, func(FAB) B) HKTB,
|
||||
|
||||
a A,
|
||||
) func(HKTFAB) HKTB {
|
||||
return func(fab HKTFAB) HKTB {
|
||||
return MonadFlap(fmap, fab, a)
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
F "github.com/IBM/fp-go/function"
|
||||
C "github.com/IBM/fp-go/internal/chain"
|
||||
FC "github.com/IBM/fp-go/internal/functor"
|
||||
L "github.com/IBM/fp-go/internal/lazy"
|
||||
)
|
||||
|
||||
@@ -143,3 +144,11 @@ func Defer[GA ~func() A, A any](gen func() GA) GA {
|
||||
return gen()()
|
||||
})
|
||||
}
|
||||
|
||||
func MonadFlap[FAB ~func(A) B, GFAB ~func() FAB, GB ~func() B, A, B any](fab GFAB, a A) GB {
|
||||
return FC.MonadFlap(MonadMap[GFAB, GB, FAB, B], fab, a)
|
||||
}
|
||||
|
||||
func Flap[FAB ~func(A) B, GFAB ~func() FAB, GB ~func() B, A, B any](a A) func(GFAB) GB {
|
||||
return F.Bind2nd(MonadFlap[FAB, GFAB, GB, A, B], a)
|
||||
}
|
||||
|
10
io/io.go
10
io/io.go
@@ -84,7 +84,7 @@ func Flatten[A any](mma IO[IO[A]]) IO[A] {
|
||||
return G.Flatten(mma)
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided IO monad lazily but exactly once
|
||||
// Memoize computes the value of the provided [IO] monad lazily but exactly once
|
||||
func Memoize[A any](ma IO[A]) IO[A] {
|
||||
return G.Memoize(ma)
|
||||
}
|
||||
@@ -138,3 +138,11 @@ var Now = G.Now[IO[time.Time]]()
|
||||
func Defer[A any](gen func() IO[A]) IO[A] {
|
||||
return G.Defer[IO[A]](gen)
|
||||
}
|
||||
|
||||
func MonadFlap[B, A any](fab IO[func(A) B], a A) IO[B] {
|
||||
return G.MonadFlap[func(A) B, IO[func(A) B], IO[B], A, B](fab, a)
|
||||
}
|
||||
|
||||
func Flap[FAB ~func(A) B, GFAB ~func() FAB, GB ~func() B, A, B any](a A) func(IO[func(A) B]) IO[B] {
|
||||
return G.Flap[func(A) B, IO[func(A) B], IO[B], A, B](a)
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
IOE "github.com/IBM/fp-go/ioeither"
|
||||
@@ -45,3 +46,10 @@ func Remove(name string) IOE.IOEither[error, string] {
|
||||
return name, os.Remove(name)
|
||||
})
|
||||
}
|
||||
|
||||
// Close closes an object
|
||||
func Close[C io.Closer](c C) IOE.IOEither[error, any] {
|
||||
return IOE.TryCatchError(func() (any, error) {
|
||||
return c, c.Close()
|
||||
})
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ func onReadAll[R io.Reader](r R) IOE.IOEither[error, []byte] {
|
||||
func ReadAll[R io.ReadCloser](acquire IOE.IOEither[error, R]) IOE.IOEither[error, []byte] {
|
||||
return IOE.WithResource[[]byte](
|
||||
acquire,
|
||||
onClose[R])(
|
||||
Close[R])(
|
||||
onReadAll[R],
|
||||
)
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ package file
|
||||
import (
|
||||
"os"
|
||||
|
||||
FL "github.com/IBM/fp-go/file"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
IO "github.com/IBM/fp-go/io"
|
||||
IOF "github.com/IBM/fp-go/io/file"
|
||||
@@ -33,7 +32,7 @@ var (
|
||||
// destroy handler
|
||||
onReleaseTempFile = F.Flow4(
|
||||
IOF.Close[*os.File],
|
||||
IO.Map(FL.GetName),
|
||||
IO.Map((*os.File).Name),
|
||||
IOE.FromIO[error, string],
|
||||
IOE.Chain(Remove),
|
||||
)
|
||||
|
@@ -38,7 +38,7 @@ func TestWithTempFileOnClosedFile(t *testing.T) {
|
||||
return F.Pipe2(
|
||||
f,
|
||||
onWriteAll[*os.File]([]byte("Carsten")),
|
||||
IOE.ChainFirst(F.Constant1[[]byte](onClose(f))),
|
||||
IOE.ChainFirst(F.Constant1[[]byte](Close(f))),
|
||||
)
|
||||
})
|
||||
|
||||
|
@@ -36,7 +36,7 @@ func WriteAll[W io.WriteCloser](data []byte) func(acquire IOE.IOEither[error, W]
|
||||
return func(onCreate IOE.IOEither[error, W]) IOE.IOEither[error, []byte] {
|
||||
return IOE.WithResource[[]byte](
|
||||
onCreate,
|
||||
onClose[W])(
|
||||
Close[W])(
|
||||
onWrite,
|
||||
)
|
||||
}
|
||||
@@ -46,5 +46,5 @@ func WriteAll[W io.WriteCloser](data []byte) func(acquire IOE.IOEither[error, W]
|
||||
func Write[R any, W io.WriteCloser](acquire IOE.IOEither[error, W]) func(use func(W) IOE.IOEither[error, R]) IOE.IOEither[error, R] {
|
||||
return IOE.WithResource[R](
|
||||
acquire,
|
||||
onClose[W])
|
||||
Close[W])
|
||||
}
|
||||
|
@@ -19,13 +19,13 @@ import (
|
||||
S "github.com/IBM/fp-go/semigroup"
|
||||
)
|
||||
|
||||
func AlternativeMonoid[A, HKTA, HKTFA any](
|
||||
func AlternativeMonoid[A, HKTA, HKTFA any, LAZYHKTA ~func() HKTA](
|
||||
fof func(A) HKTA,
|
||||
|
||||
fmap func(HKTA, func(A) func(A) A) HKTFA,
|
||||
fap func(HKTFA, HKTA) HKTA,
|
||||
|
||||
falt func(HKTA, func() HKTA) HKTA,
|
||||
falt func(HKTA, LAZYHKTA) HKTA,
|
||||
|
||||
m Monoid[A],
|
||||
|
||||
@@ -45,9 +45,9 @@ func AlternativeMonoid[A, HKTA, HKTFA any](
|
||||
)
|
||||
}
|
||||
|
||||
func AltMonoid[HKTA any](
|
||||
fzero func() HKTA,
|
||||
falt func(HKTA, func() HKTA) HKTA,
|
||||
func AltMonoid[HKTA any, LAZYHKTA ~func() HKTA](
|
||||
fzero LAZYHKTA,
|
||||
falt func(HKTA, LAZYHKTA) HKTA,
|
||||
|
||||
) Monoid[HKTA] {
|
||||
|
||||
|
@@ -51,3 +51,22 @@ func Monoid[A any]() func(S.Semigroup[A]) M.Monoid[Option[A]] {
|
||||
return M.MakeMonoid(sg(s).Concat, None[A]())
|
||||
}
|
||||
}
|
||||
|
||||
// AlternativeMonoid is the alternative [Monoid] for an [Option]
|
||||
func AlternativeMonoid[A any](m M.Monoid[A]) M.Monoid[Option[A]] {
|
||||
return M.AlternativeMonoid(
|
||||
Of[A],
|
||||
MonadMap[A, func(A) A],
|
||||
MonadAp[A, A],
|
||||
MonadAlt[A],
|
||||
m,
|
||||
)
|
||||
}
|
||||
|
||||
// AltMonoid is the alternative [Monoid] for an [Option]
|
||||
func AltMonoid[A any]() M.Monoid[Option[A]] {
|
||||
return M.AltMonoid(
|
||||
None[A],
|
||||
MonadAlt[A],
|
||||
)
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package option
|
||||
|
||||
import (
|
||||
F "github.com/IBM/fp-go/function"
|
||||
FC "github.com/IBM/fp-go/internal/functor"
|
||||
)
|
||||
|
||||
func fromPredicate[A any](a A, pred func(A) bool) Option[A] {
|
||||
@@ -115,6 +116,10 @@ func Flatten[A any](mma Option[Option[A]]) Option[A] {
|
||||
return MonadChain(mma, F.Identity[Option[A]])
|
||||
}
|
||||
|
||||
func MonadAlt[A any](fa Option[A], that func() Option[A]) Option[A] {
|
||||
return MonadFold(fa, that, Of[A])
|
||||
}
|
||||
|
||||
func Alt[A any](that func() Option[A]) func(Option[A]) Option[A] {
|
||||
return Fold(that, Of[A])
|
||||
}
|
||||
@@ -141,3 +146,11 @@ func Reduce[A, B any](f func(B, A) B, initial B) func(Option[A]) B {
|
||||
func Filter[A any](pred func(A) bool) func(Option[A]) Option[A] {
|
||||
return Fold(None[A], F.Ternary(pred, Of[A], F.Ignore1of1[A](None[A])))
|
||||
}
|
||||
|
||||
func MonadFlap[B, A any](fab Option[func(A) B], a A) Option[B] {
|
||||
return FC.MonadFlap(MonadMap[func(A) B, B], fab, a)
|
||||
}
|
||||
|
||||
func Flap[B, A any](a A) func(Option[func(A) B]) Option[B] {
|
||||
return F.Bind2nd(MonadFlap[B, A], a)
|
||||
}
|
||||
|
@@ -16,7 +16,10 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
F "github.com/IBM/fp-go/function"
|
||||
FIO "github.com/IBM/fp-go/internal/fromio"
|
||||
FR "github.com/IBM/fp-go/internal/fromreader"
|
||||
"github.com/IBM/fp-go/internal/readert"
|
||||
IO "github.com/IBM/fp-go/io/generic"
|
||||
@@ -84,11 +87,37 @@ func Asks[GA ~func(E) A, GEA ~func(E) GIOA, GIOA ~func() A, E, A any](r GA) GEA
|
||||
}
|
||||
|
||||
func MonadChainIOK[GEA ~func(E) GIOA, GEB ~func(E) GIOB, GIOA ~func() A, GIOB ~func() B, E, A, B any](ma GEA, f func(A) GIOB) GEB {
|
||||
return MonadChain(ma, F.Flow2(f, FromIO[GEB]))
|
||||
return FIO.MonadChainIOK(
|
||||
MonadChain[GEA, GEB],
|
||||
FromIO[GEB],
|
||||
ma, f,
|
||||
)
|
||||
}
|
||||
|
||||
func ChainIOK[GEA ~func(E) GIOA, GEB ~func(E) GIOB, GIOA ~func() A, GIOB ~func() B, E, A, B any](f func(A) GIOB) func(GEA) GEB {
|
||||
return F.Bind2nd(MonadChainIOK[GEA, GEB, GIOA, GIOB, E, A, B], f)
|
||||
return FIO.ChainIOK(
|
||||
MonadChain[GEA, GEB],
|
||||
FromIO[GEB],
|
||||
f,
|
||||
)
|
||||
}
|
||||
|
||||
func MonadChainFirstIOK[GEA ~func(E) GIOA, GEB ~func(E) GIOB, GIOA ~func() A, GIOB ~func() B, E, A, B any](ma GEA, f func(A) GIOB) GEA {
|
||||
return FIO.MonadChainFirstIOK(
|
||||
MonadChain[GEA, GEA],
|
||||
MonadMap[GEB, GEA],
|
||||
FromIO[GEB],
|
||||
ma, f,
|
||||
)
|
||||
}
|
||||
|
||||
func ChainFirstIOK[GEA ~func(E) GIOA, GEB ~func(E) GIOB, GIOA ~func() A, GIOB ~func() B, E, A, B any](f func(A) GIOB) func(GEA) GEA {
|
||||
return FIO.ChainFirstIOK(
|
||||
MonadChain[GEA, GEA],
|
||||
MonadMap[GEB, GEA],
|
||||
FromIO[GEB],
|
||||
f,
|
||||
)
|
||||
}
|
||||
|
||||
// Defer creates an IO by creating a brand new IO via a generator function, each time
|
||||
@@ -99,3 +128,30 @@ func Defer[GEA ~func(E) GA, GA ~func() A, E, A any](gen func() GEA) GEA {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided reader monad lazily but exactly once
|
||||
// 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
|
||||
func Memoize[GEA ~func(E) GA, GA ~func() A, E, A any](rdr GEA) GEA {
|
||||
// synchronization primitives
|
||||
var once sync.Once
|
||||
var result A
|
||||
// callback
|
||||
gen := func(e E) func() {
|
||||
return func() {
|
||||
result = rdr(e)()
|
||||
}
|
||||
}
|
||||
// returns our memoized wrapper
|
||||
return func(e E) GA {
|
||||
io := gen(e)
|
||||
return func() A {
|
||||
once.Do(io)
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Flatten[GEA ~func(R) GIOA, GGEA ~func(R) GIOEA, GIOA ~func() A, GIOEA ~func() GEA, R, A any](mma GGEA) GEA {
|
||||
return MonadChain(mma, F.Identity[GEA])
|
||||
}
|
||||
|
@@ -75,3 +75,14 @@ func ChainIOK[E, A, B any](f func(A) IO.IO[B]) func(ReaderIO[E, A]) ReaderIO[E,
|
||||
func Defer[E, A any](gen func() ReaderIO[E, A]) ReaderIO[E, A] {
|
||||
return G.Defer[ReaderIO[E, A]](gen)
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided [ReaderIO] monad lazily but exactly once
|
||||
// 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
|
||||
func Memoize[E, A any](rdr ReaderIO[E, A]) ReaderIO[E, A] {
|
||||
return G.Memoize[ReaderIO[E, A]](rdr)
|
||||
}
|
||||
|
||||
func Flatten[E, A any](mma ReaderIO[E, ReaderIO[E, A]]) ReaderIO[E, A] {
|
||||
return G.Flatten[ReaderIO[E, A], ReaderIO[E, ReaderIO[E, A]]](mma)
|
||||
}
|
||||
|
@@ -147,6 +147,23 @@ func ChainReaderK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E
|
||||
)
|
||||
}
|
||||
|
||||
func MonadChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() ET.Either[E, A], GIOEB ~func() ET.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](ma GEA, f func(A) GB) GEB {
|
||||
return FR.MonadChainReaderK(
|
||||
MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B],
|
||||
RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B],
|
||||
ma,
|
||||
f,
|
||||
)
|
||||
}
|
||||
|
||||
func ChainReaderIOK[GEA ~func(R) GIOEA, GEB ~func(R) GIOEB, GIOEA ~func() ET.Either[E, A], GIOEB ~func() ET.Either[E, B], GIOB ~func() B, GB ~func(R) GIOB, R, E, A, B any](f func(A) GB) func(GEA) GEB {
|
||||
return FR.ChainReaderK(
|
||||
MonadChain[GEA, GEB, GIOEA, GIOEB, R, E, A, B],
|
||||
RightReaderIO[GEB, GIOEB, GB, GIOB, R, E, B],
|
||||
f,
|
||||
)
|
||||
}
|
||||
|
||||
func MonadChainIOEitherK[GEA ~func(R) GIOA, GEB ~func(R) GIOB, GIOA ~func() ET.Either[E, A], GIOB ~func() ET.Either[E, B], R, E, A, B any](ma GEA, f func(A) GIOB) GEB {
|
||||
return FIOE.MonadChainIOEitherK(
|
||||
MonadChain[GEA, GEB, GIOA, GIOB, R, E, A, B],
|
||||
@@ -406,3 +423,11 @@ func TryCatch[GEA ~func(R) GA, GA ~func() ET.Either[E, A], R, E, A any](f func(R
|
||||
return IOE.TryCatch[GA](f(r), onThrow)
|
||||
}
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided monad lazily but exactly once
|
||||
// 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
|
||||
func Memoize[
|
||||
GEA ~func(R) GIOA, GIOA ~func() ET.Either[E, A], R, E, A any](rdr GEA) GEA {
|
||||
return G.Memoize[GEA](rdr)
|
||||
}
|
||||
|
@@ -264,3 +264,11 @@ func MonadAlt[R, E, A any](first ReaderIOEither[R, E, A], second L.Lazy[ReaderIO
|
||||
func Alt[R, E, A any](second L.Lazy[ReaderIOEither[R, E, A]]) func(ReaderIOEither[R, E, A]) ReaderIOEither[R, E, A] {
|
||||
return G.Alt(second)
|
||||
}
|
||||
|
||||
// Memoize computes the value of the provided [ReaderIOEither] monad lazily but exactly once
|
||||
// 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
|
||||
func Memoize[
|
||||
R, E, A any](rdr ReaderIOEither[R, E, A]) ReaderIOEither[R, E, A] {
|
||||
return G.Memoize[ReaderIOEither[R, E, A]](rdr)
|
||||
}
|
||||
|
65
samples/match/examples_match_test.go
Normal file
65
samples/match/examples_match_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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 match
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
E "github.com/IBM/fp-go/either"
|
||||
"github.com/IBM/fp-go/errors"
|
||||
F "github.com/IBM/fp-go/function"
|
||||
O "github.com/IBM/fp-go/option"
|
||||
S "github.com/IBM/fp-go/string"
|
||||
)
|
||||
|
||||
type Thing struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (t Thing) GetName() string {
|
||||
return t.Name
|
||||
}
|
||||
|
||||
var (
|
||||
// func(Thing) Either[error, string]
|
||||
getName = F.Flow2(
|
||||
Thing.GetName,
|
||||
E.FromPredicate(S.IsNonEmpty, errors.OnSome[string]("value [%s] is empty")),
|
||||
)
|
||||
|
||||
// func(option.Option[Thing]) Either[error, string]
|
||||
GetName = F.Flow2(
|
||||
E.FromOption[Thing](errors.OnNone("value is none")),
|
||||
E.Chain(getName),
|
||||
)
|
||||
)
|
||||
|
||||
func ExampleEither_match() {
|
||||
|
||||
oThing := O.Of(Thing{"Carsten"})
|
||||
|
||||
res := F.Pipe2(
|
||||
oThing,
|
||||
GetName,
|
||||
E.Fold(S.Format[error]("failed with error %v"), S.Format[string]("get value %s")),
|
||||
)
|
||||
|
||||
fmt.Println(res)
|
||||
|
||||
// Output:
|
||||
// get value Carsten
|
||||
|
||||
}
|
@@ -15,8 +15,8 @@
|
||||
|
||||
package semigroup
|
||||
|
||||
func AltSemigroup[HKTA any](
|
||||
falt func(HKTA, func() HKTA) HKTA,
|
||||
func AltSemigroup[HKTA any, LAZYHKTA ~func() HKTA](
|
||||
falt func(HKTA, LAZYHKTA) HKTA,
|
||||
|
||||
) Semigroup[HKTA] {
|
||||
|
||||
|
Reference in New Issue
Block a user