mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-23 00:27:49 +02:00
fix: automate eitherize methods
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# Functional programming library for golang
|
||||
|
||||
**Work in progress!**
|
||||
**🚧 Work in progress! 🚧**
|
||||
|
||||

|
||||
|
||||
|
@ -13,5 +13,8 @@ func Commands() []*C.Command {
|
||||
TupleCommand(),
|
||||
BindCommand(),
|
||||
ApplyCommand(),
|
||||
ContextReaderIOEitherCommand(),
|
||||
ReaderIOEitherCommand(),
|
||||
ReaderCommand(),
|
||||
}
|
||||
}
|
||||
|
143
cli/contextreaderioeither.go
Normal file
143
cli/contextreaderioeither.go
Normal file
@ -0,0 +1,143 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
C "github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func generateContextReaderIOEitherEitherize(f, fg *os.File, i int) {
|
||||
// non generic version
|
||||
fmt.Fprintf(f, "\n// Eitherize%d converts a function with %d parameters returning a tuple into a function with %d parameters returning a [ReaderIOEither[R]]\n// The inverse function is [Uneitherize%d]\n", i, i, i, i)
|
||||
fmt.Fprintf(f, "func Eitherize%d[F ~func(context.Context", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") (R, error)")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ", R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(f, ", ")
|
||||
}
|
||||
fmt.Fprintf(f, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") ReaderIOEither[R] {\n")
|
||||
fmt.Fprintf(f, " return G.Eitherize%d[ReaderIOEither[R]](f)\n", i)
|
||||
fmt.Fprintln(f, "}")
|
||||
|
||||
// generic version
|
||||
fmt.Fprintf(fg, "\n// Eitherize%d converts a function with %d parameters returning a tuple into a function with %d parameters returning a [GRA]\n// The inverse function is [Uneitherize%d]\n", i, i, i, i)
|
||||
fmt.Fprintf(fg, "func Eitherize%d[GRA ~func(context.Context) GIOA, F ~func(context.Context", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") (R, error), GIOA ~func() E.Either[error, R]")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ", R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(fg, ", ")
|
||||
}
|
||||
fmt.Fprintf(fg, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") GRA {\n")
|
||||
fmt.Fprintf(fg, " return RE.Eitherize%d[GRA](f)\n", i)
|
||||
fmt.Fprintln(fg, "}")
|
||||
}
|
||||
|
||||
func generateContextReaderIOEitherHelpers(filename string, count int) error {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
absDir, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pkg := filepath.Base(absDir)
|
||||
f, err := os.Create(filepath.Clean(filename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
// construct subdirectory
|
||||
genFilename := filepath.Join("generic", filename)
|
||||
err = os.MkdirAll("generic", os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fg, err := os.Create(filepath.Clean(genFilename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fg.Close()
|
||||
|
||||
// log
|
||||
log.Printf("Generating code in [%s] for package [%s] with [%d] repetitions ...", filename, pkg, count)
|
||||
|
||||
// some header
|
||||
fmt.Fprintln(f, "// Code generated by go generate; DO NOT EDIT.")
|
||||
fmt.Fprintln(f, "// This file was generated by robots at")
|
||||
fmt.Fprintf(f, "// %s\n", time.Now())
|
||||
|
||||
fmt.Fprintf(f, "package %s\n\n", pkg)
|
||||
|
||||
fmt.Fprintf(f, `
|
||||
import (
|
||||
"context"
|
||||
|
||||
G "github.com/ibm/fp-go/context/%s/generic"
|
||||
)
|
||||
`, pkg)
|
||||
|
||||
// some header
|
||||
fmt.Fprintln(fg, "// Code generated by go generate; DO NOT EDIT.")
|
||||
fmt.Fprintln(fg, "// This file was generated by robots at")
|
||||
fmt.Fprintf(fg, "// %s\n", time.Now())
|
||||
|
||||
fmt.Fprintf(fg, "package generic\n\n")
|
||||
|
||||
fmt.Fprintf(fg, `
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
`)
|
||||
|
||||
generateContextReaderIOEitherEitherize(f, fg, 0)
|
||||
|
||||
for i := 1; i <= count; i++ {
|
||||
// eitherize
|
||||
generateContextReaderIOEitherEitherize(f, fg, i)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ContextReaderIOEitherCommand() *C.Command {
|
||||
return &C.Command{
|
||||
Name: "contextreaderioeither",
|
||||
Usage: "generate code for ContextReaderIOEither",
|
||||
Flags: []C.Flag{
|
||||
flagCount,
|
||||
flagFilename,
|
||||
},
|
||||
Action: func(ctx *C.Context) error {
|
||||
return generateContextReaderIOEitherHelpers(
|
||||
ctx.String(keyFilename),
|
||||
ctx.Int(keyCount),
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
163
cli/reader.go
Normal file
163
cli/reader.go
Normal file
@ -0,0 +1,163 @@
|
||||
// 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 cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
C "github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func generateReaderFrom(f, fg *os.File, i int) {
|
||||
// non generic version
|
||||
fmt.Fprintf(f, "\n// From%d converts a function with %d parameters returning a [R] into a function with %d parameters returning a [Reader[C, R]]\n// The first parameter is considered to be the context [C] of the reader\n", i, i+1, i)
|
||||
fmt.Fprintf(f, "func From%d[F ~func(C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") R")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ", C, R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(f, ", ")
|
||||
}
|
||||
fmt.Fprintf(f, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") Reader[C, R] {\n")
|
||||
fmt.Fprintf(f, " return G.From%d[Reader[C, R]](f)\n", i)
|
||||
fmt.Fprintln(f, "}")
|
||||
|
||||
// generic version
|
||||
fmt.Fprintf(fg, "\n// From%d converts a function with %d parameters returning a [R] into a function with %d parameters returning a [GRA]\n// The first parameter is considered to be the context [C].\n", i, i+1, i)
|
||||
fmt.Fprintf(fg, "func From%d[GRA ~func(C) R, F ~func(C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") R")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ", C, R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(fg, ", ")
|
||||
}
|
||||
fmt.Fprintf(fg, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") GRA {\n")
|
||||
|
||||
fmt.Fprintf(fg, " return func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(fg, ", ")
|
||||
}
|
||||
fmt.Fprintf(fg, "t%d T%d", j, j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") GRA {\n")
|
||||
fmt.Fprintf(fg, " return MakeReader[GRA](func(r C) R {\n")
|
||||
fmt.Fprintf(fg, " return f(r")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", t%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ")\n")
|
||||
fmt.Fprintf(fg, " })\n")
|
||||
fmt.Fprintf(fg, " }\n")
|
||||
fmt.Fprintf(fg, "}\n")
|
||||
}
|
||||
|
||||
func generateReaderHelpers(filename string, count int) error {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
absDir, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pkg := filepath.Base(absDir)
|
||||
f, err := os.Create(filepath.Clean(filename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
// construct subdirectory
|
||||
genFilename := filepath.Join("generic", filename)
|
||||
err = os.MkdirAll("generic", os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fg, err := os.Create(filepath.Clean(genFilename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fg.Close()
|
||||
|
||||
// log
|
||||
log.Printf("Generating code in [%s] for package [%s] with [%d] repetitions ...", filename, pkg, count)
|
||||
|
||||
// some header
|
||||
fmt.Fprintln(f, "// Code generated by go generate; DO NOT EDIT.")
|
||||
fmt.Fprintln(f, "// This file was generated by robots at")
|
||||
fmt.Fprintf(f, "// %s\n", time.Now())
|
||||
|
||||
fmt.Fprintf(f, "package %s\n\n", pkg)
|
||||
|
||||
fmt.Fprintf(f, `
|
||||
import (
|
||||
G "github.com/ibm/fp-go/%s/generic"
|
||||
)
|
||||
`, pkg)
|
||||
|
||||
// some header
|
||||
fmt.Fprintln(fg, "// Code generated by go generate; DO NOT EDIT.")
|
||||
fmt.Fprintln(fg, "// This file was generated by robots at")
|
||||
fmt.Fprintf(fg, "// %s\n", time.Now())
|
||||
|
||||
fmt.Fprintf(fg, "package generic\n\n")
|
||||
|
||||
// from
|
||||
generateReaderFrom(f, fg, 0)
|
||||
|
||||
for i := 1; i <= count; i++ {
|
||||
// from
|
||||
generateReaderFrom(f, fg, i)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReaderCommand() *C.Command {
|
||||
return &C.Command{
|
||||
Name: "reader",
|
||||
Usage: "generate code for Reader",
|
||||
Flags: []C.Flag{
|
||||
flagCount,
|
||||
flagFilename,
|
||||
},
|
||||
Action: func(ctx *C.Context) error {
|
||||
return generateReaderHelpers(
|
||||
ctx.String(keyFilename),
|
||||
ctx.Int(keyCount),
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
211
cli/readerioeither.go
Normal file
211
cli/readerioeither.go
Normal file
@ -0,0 +1,211 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
C "github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func generateReaderIOEitherFrom(f, fg *os.File, i int) {
|
||||
// non generic version
|
||||
fmt.Fprintf(f, "\n// From%d converts a function with %d parameters returning a tuple into a function with %d parameters returning a [ReaderIOEither[R]]\n// The first parameter is considered to be the context [C].\n", i, i+1, i)
|
||||
fmt.Fprintf(f, "func From%d[F ~func(C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") func() (R, error)")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ", C, R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(f, ", ")
|
||||
}
|
||||
fmt.Fprintf(f, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") ReaderIOEither[C, error, R] {\n")
|
||||
fmt.Fprintf(f, " return G.From%d[ReaderIOEither[C, error, R]](f)\n", i)
|
||||
fmt.Fprintln(f, "}")
|
||||
|
||||
// generic version
|
||||
fmt.Fprintf(fg, "\n// From%d converts a function with %d parameters returning a tuple into a function with %d parameters returning a [GRA]\n// The first parameter is considerd to be the context [C].\n", i, i+1, i)
|
||||
fmt.Fprintf(fg, "func From%d[GRA ~func(C) GIOA, F ~func(C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") func() (R, error), GIOA ~func() E.Either[error, R]")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ", C, R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(fg, ", ")
|
||||
}
|
||||
fmt.Fprintf(fg, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") GRA {\n")
|
||||
|
||||
fmt.Fprintf(fg, " return RD.From%d[GRA](func(r C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", t%d T%d", j, j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") GIOA {\n")
|
||||
fmt.Fprintf(fg, " return E.Eitherize0(f(r")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", t%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, "))\n")
|
||||
fmt.Fprintf(fg, " })\n")
|
||||
fmt.Fprintf(fg, "}\n")
|
||||
}
|
||||
|
||||
func generateReaderIOEitherEitherize(f, fg *os.File, i int) {
|
||||
// non generic version
|
||||
fmt.Fprintf(f, "\n// Eitherize%d converts a function with %d parameters returning a tuple into a function with %d parameters returning a [ReaderIOEither[C, error, R]]\n// The first parameter is considered to be the context [C].\n", i, i+1, i)
|
||||
fmt.Fprintf(f, "func Eitherize%d[F ~func(C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") (R, error)")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(f, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ", C, R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(f, ", ")
|
||||
}
|
||||
fmt.Fprintf(f, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(f, ") ReaderIOEither[C, error, R] {\n")
|
||||
fmt.Fprintf(f, " return G.Eitherize%d[ReaderIOEither[C, error, R]](f)\n", i)
|
||||
fmt.Fprintln(f, "}")
|
||||
|
||||
// generic version
|
||||
fmt.Fprintf(fg, "\n// Eitherize%d converts a function with %d parameters returning a tuple into a function with %d parameters returning a [GRA]\n// The first parameter is considered to be the context [C].\n", i, i, i)
|
||||
fmt.Fprintf(fg, "func Eitherize%d[GRA ~func(C) GIOA, F ~func(C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") (R, error), GIOA ~func() E.Either[error, R]")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ", C, R any](f F) func(")
|
||||
for j := 0; j < i; j++ {
|
||||
if j > 0 {
|
||||
fmt.Fprintf(fg, ", ")
|
||||
}
|
||||
fmt.Fprintf(fg, "T%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") GRA {\n")
|
||||
|
||||
fmt.Fprintf(fg, " return From%d[GRA](func(r C", i)
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", t%d T%d", j, j)
|
||||
}
|
||||
fmt.Fprintf(fg, ") func() (R, error) {\n")
|
||||
fmt.Fprintf(fg, " return func() (R, error) {\n")
|
||||
fmt.Fprintf(fg, " return f(r")
|
||||
for j := 0; j < i; j++ {
|
||||
fmt.Fprintf(fg, ", t%d", j)
|
||||
}
|
||||
fmt.Fprintf(fg, ")\n")
|
||||
fmt.Fprintf(fg, " }})\n")
|
||||
fmt.Fprintf(fg, "}\n")
|
||||
}
|
||||
|
||||
func generateReaderIOEitherHelpers(filename string, count int) error {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
absDir, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pkg := filepath.Base(absDir)
|
||||
f, err := os.Create(filepath.Clean(filename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
// construct subdirectory
|
||||
genFilename := filepath.Join("generic", filename)
|
||||
err = os.MkdirAll("generic", os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fg, err := os.Create(filepath.Clean(genFilename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fg.Close()
|
||||
|
||||
// log
|
||||
log.Printf("Generating code in [%s] for package [%s] with [%d] repetitions ...", filename, pkg, count)
|
||||
|
||||
// some header
|
||||
fmt.Fprintln(f, "// Code generated by go generate; DO NOT EDIT.")
|
||||
fmt.Fprintln(f, "// This file was generated by robots at")
|
||||
fmt.Fprintf(f, "// %s\n", time.Now())
|
||||
|
||||
fmt.Fprintf(f, "package %s\n\n", pkg)
|
||||
|
||||
fmt.Fprintf(f, `
|
||||
import (
|
||||
G "github.com/ibm/fp-go/%s/generic"
|
||||
)
|
||||
`, pkg)
|
||||
|
||||
// some header
|
||||
fmt.Fprintln(fg, "// Code generated by go generate; DO NOT EDIT.")
|
||||
fmt.Fprintln(fg, "// This file was generated by robots at")
|
||||
fmt.Fprintf(fg, "// %s\n", time.Now())
|
||||
|
||||
fmt.Fprintf(fg, "package generic\n\n")
|
||||
|
||||
fmt.Fprintf(fg, `
|
||||
import (
|
||||
E "github.com/ibm/fp-go/either"
|
||||
RD "github.com/ibm/fp-go/reader/generic"
|
||||
)
|
||||
`)
|
||||
|
||||
// from
|
||||
generateReaderIOEitherFrom(f, fg, 0)
|
||||
// eitherize
|
||||
generateReaderIOEitherEitherize(f, fg, 0)
|
||||
|
||||
for i := 1; i <= count; i++ {
|
||||
// from
|
||||
generateReaderIOEitherFrom(f, fg, i)
|
||||
// eitherize
|
||||
generateReaderIOEitherEitherize(f, fg, i)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReaderIOEitherCommand() *C.Command {
|
||||
return &C.Command{
|
||||
Name: "readerioeither",
|
||||
Usage: "generate code for ReaderIOEither",
|
||||
Flags: []C.Flag{
|
||||
flagCount,
|
||||
flagFilename,
|
||||
},
|
||||
Action: func(ctx *C.Context) error {
|
||||
return generateReaderIOEitherHelpers(
|
||||
ctx.String(keyFilename),
|
||||
ctx.Int(keyCount),
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
15
context/doc.go
Normal file
15
context/doc.go
Normal file
@ -0,0 +1,15 @@
|
||||
// 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 context
|
19
context/ioeither/generic/ioeither.go
Normal file
19
context/ioeither/generic/ioeither.go
Normal file
@ -0,0 +1,19 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
ET "github.com/ibm/fp-go/either"
|
||||
IOE "github.com/ibm/fp-go/ioeither/generic"
|
||||
)
|
||||
|
||||
// withContext wraps an existing IOEither and performs a context check for cancellation before delegating
|
||||
func WithContext[GIO ~func() E.Either[error, A], A any](ctx context.Context, ma GIO) GIO {
|
||||
return IOE.MakeIO[GIO](func() E.Either[error, A] {
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return ET.Left[A](err)
|
||||
}
|
||||
return ma()
|
||||
})
|
||||
}
|
@ -3,16 +3,11 @@ package ioeither
|
||||
import (
|
||||
"context"
|
||||
|
||||
ET "github.com/ibm/fp-go/either"
|
||||
G "github.com/ibm/fp-go/context/ioeither/generic"
|
||||
IOE "github.com/ibm/fp-go/ioeither"
|
||||
)
|
||||
|
||||
// withContext wraps an existing IOEither and performs a context check for cancellation before delegating
|
||||
func WithContext[A any](ctx context.Context, ma IOE.IOEither[error, A]) IOE.IOEither[error, A] {
|
||||
return IOE.MakeIO(func() ET.Either[error, A] {
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return ET.Left[A](err)
|
||||
}
|
||||
return ma()
|
||||
})
|
||||
return G.WithContext(ctx, ma)
|
||||
}
|
||||
|
@ -1,3 +1,18 @@
|
||||
// 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 reader
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,18 @@
|
||||
// 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 reader
|
||||
|
||||
import (
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
// these functions curry a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[A any](f func(context.Context) A) Reader[A] {
|
||||
func From0[A any](f func(context.Context) A) func() Reader[A] {
|
||||
return R.From0[Reader[A]](f)
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
// these functions curry a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[A any](f func(context.Context) (A, error)) ReaderEither[A] {
|
||||
func From0[A any](f func(context.Context) (A, error)) func() ReaderEither[A] {
|
||||
return RE.From0[ReaderEither[A]](f)
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
// these functions curry a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[A any](f func(context.Context) IO.IO[A]) ReaderIO[A] {
|
||||
func From0[A any](f func(context.Context) IO.IO[A]) func() ReaderIO[A] {
|
||||
return R.From0[ReaderIO[A]](f)
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,10 @@
|
||||
package readerioeither
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
CIOE "github.com/ibm/fp-go/context/ioeither"
|
||||
IOE "github.com/ibm/fp-go/ioeither"
|
||||
G "github.com/ibm/fp-go/context/readerioeither/generic"
|
||||
)
|
||||
|
||||
// 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] {
|
||||
return func(ctx context.Context) IOE.IOEither[error, A] {
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return IOE.Left[A](err)
|
||||
}
|
||||
return CIOE.WithContext(ctx, ma(ctx))
|
||||
}
|
||||
return G.WithContext(ma)
|
||||
}
|
||||
|
3
context/readerioeither/doc.go
Normal file
3
context/readerioeither/doc.go
Normal file
@ -0,0 +1,3 @@
|
||||
package readerioeither
|
||||
|
||||
//go:generate go run ../.. contextreaderioeither --count 10 --filename gen.go
|
@ -1,30 +0,0 @@
|
||||
package readerioeither
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// these functions curry a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func Eitherize0[A any](f func(context.Context) (A, error)) ReaderIOEither[A] {
|
||||
return RE.Eitherize0[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func Eitherize1[T1, A any](f func(context.Context, T1) (A, error)) func(T1) ReaderIOEither[A] {
|
||||
return RE.Eitherize1[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func Eitherize2[T1, T2, A any](f func(context.Context, T1, T2) (A, error)) func(T1, T2) ReaderIOEither[A] {
|
||||
return RE.Eitherize2[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func Eitherize3[T1, T2, T3, A any](f func(context.Context, T1, T2, T3) (A, error)) func(T1, T2, T3) ReaderIOEither[A] {
|
||||
return RE.Eitherize3[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func Eitherize4[T1, T2, T3, T4, A any](f func(context.Context, T1, T2, T3, T4) (A, error)) func(T1, T2, T3, T4) ReaderIOEither[A] {
|
||||
return RE.Eitherize4[ReaderIOEither[A]](f)
|
||||
}
|
@ -3,9 +3,9 @@ package readerioeither
|
||||
import (
|
||||
"context"
|
||||
|
||||
G "github.com/ibm/fp-go/context/readerioeither/generic"
|
||||
ET "github.com/ibm/fp-go/either"
|
||||
EQ "github.com/ibm/fp-go/eq"
|
||||
G "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// Eq implements the equals predicate for values contained in the IOEither monad
|
||||
|
@ -1,30 +0,0 @@
|
||||
package readerioeither
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// these functions curry a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[A any](f func(context.Context) func() (A, error)) ReaderIOEither[A] {
|
||||
return RE.From0[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func From1[T1, A any](f func(context.Context, T1) func() (A, error)) func(T1) ReaderIOEither[A] {
|
||||
return RE.From1[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func From2[T1, T2, A any](f func(context.Context, T1, T2) func() (A, error)) func(T1, T2) ReaderIOEither[A] {
|
||||
return RE.From2[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func From3[T1, T2, T3, A any](f func(context.Context, T1, T2, T3) func() (A, error)) func(T1, T2, T3) ReaderIOEither[A] {
|
||||
return RE.From3[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func From4[T1, T2, T3, T4, A any](f func(context.Context, T1, T2, T3, T4) func() (A, error)) func(T1, T2, T3, T4) ReaderIOEither[A] {
|
||||
return RE.From4[ReaderIOEither[A]](f)
|
||||
}
|
77
context/readerioeither/gen.go
Normal file
77
context/readerioeither/gen.go
Normal file
@ -0,0 +1,77 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-18 15:21:14.8906482 +0200 CEST m=+0.127356001
|
||||
package readerioeither
|
||||
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
G "github.com/ibm/fp-go/context/readerioeither/generic"
|
||||
)
|
||||
|
||||
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize0]
|
||||
func Eitherize0[F ~func(context.Context) (R, error), R any](f F) func() ReaderIOEither[R] {
|
||||
return G.Eitherize0[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize1]
|
||||
func Eitherize1[F ~func(context.Context, T0) (R, error), T0, R any](f F) func(T0) ReaderIOEither[R] {
|
||||
return G.Eitherize1[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize2]
|
||||
func Eitherize2[F ~func(context.Context, T0, T1) (R, error), T0, T1, R any](f F) func(T0, T1) ReaderIOEither[R] {
|
||||
return G.Eitherize2[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize3]
|
||||
func Eitherize3[F ~func(context.Context, T0, T1, T2) (R, error), T0, T1, T2, R any](f F) func(T0, T1, T2) ReaderIOEither[R] {
|
||||
return G.Eitherize3[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize4]
|
||||
func Eitherize4[F ~func(context.Context, T0, T1, T2, T3) (R, error), T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) ReaderIOEither[R] {
|
||||
return G.Eitherize4[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize5]
|
||||
func Eitherize5[F ~func(context.Context, T0, T1, T2, T3, T4) (R, error), T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) ReaderIOEither[R] {
|
||||
return G.Eitherize5[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize6]
|
||||
func Eitherize6[F ~func(context.Context, T0, T1, T2, T3, T4, T5) (R, error), T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) ReaderIOEither[R] {
|
||||
return G.Eitherize6[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize7]
|
||||
func Eitherize7[F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6) (R, error), T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) ReaderIOEither[R] {
|
||||
return G.Eitherize7[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize8]
|
||||
func Eitherize8[F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) ReaderIOEither[R] {
|
||||
return G.Eitherize8[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize9]
|
||||
func Eitherize9[F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) ReaderIOEither[R] {
|
||||
return G.Eitherize9[ReaderIOEither[R]](f)
|
||||
}
|
||||
|
||||
// Eitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning a [ReaderIOEither[R]]
|
||||
// The inverse function is [Uneitherize10]
|
||||
func Eitherize10[F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) ReaderIOEither[R] {
|
||||
return G.Eitherize10[ReaderIOEither[R]](f)
|
||||
}
|
19
context/readerioeither/generic/cancel.go
Normal file
19
context/readerioeither/generic/cancel.go
Normal file
@ -0,0 +1,19 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
CIOE "github.com/ibm/fp-go/context/ioeither/generic"
|
||||
E "github.com/ibm/fp-go/either"
|
||||
IOE "github.com/ibm/fp-go/ioeither/generic"
|
||||
)
|
||||
|
||||
// withContext wraps an existing ReaderIOEither and performs a context check for cancellation before delegating
|
||||
func WithContext[GRA ~func(context.Context) GIOA, GIOA ~func() E.Either[error, A], A any](ma GRA) GRA {
|
||||
return func(ctx context.Context) GIOA {
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return IOE.Left[GIOA](err)
|
||||
}
|
||||
return CIOE.WithContext(ctx, ma(ctx))
|
||||
}
|
||||
}
|
15
context/readerioeither/generic/eq.go
Normal file
15
context/readerioeither/generic/eq.go
Normal file
@ -0,0 +1,15 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
ET "github.com/ibm/fp-go/either"
|
||||
EQ "github.com/ibm/fp-go/eq"
|
||||
G "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// Eq implements the equals predicate for values contained in the IOEither monad
|
||||
func Eq[GRA ~func(context.Context) GIOA, GIOA ~func() E.Either[error, A], A any](eq EQ.Eq[ET.Either[error, A]]) func(context.Context) EQ.Eq[GRA] {
|
||||
return G.Eq[GRA](eq)
|
||||
}
|
78
context/readerioeither/generic/gen.go
Normal file
78
context/readerioeither/generic/gen.go
Normal file
@ -0,0 +1,78 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-18 15:21:14.8906482 +0200 CEST m=+0.127356001
|
||||
package generic
|
||||
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize0]
|
||||
func Eitherize0[GRA ~func(context.Context) GIOA, F ~func(context.Context) (R, error), GIOA ~func() E.Either[error, R], R any](f F) func() GRA {
|
||||
return RE.Eitherize0[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize1]
|
||||
func Eitherize1[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0) (R, error), GIOA ~func() E.Either[error, R], T0, R any](f F) func(T0) GRA {
|
||||
return RE.Eitherize1[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize2]
|
||||
func Eitherize2[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1) (R, error), GIOA ~func() E.Either[error, R], T0, T1, R any](f F) func(T0, T1) GRA {
|
||||
return RE.Eitherize2[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize3]
|
||||
func Eitherize3[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, R any](f F) func(T0, T1, T2) GRA {
|
||||
return RE.Eitherize3[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize4]
|
||||
func Eitherize4[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, R any](f F) func(T0, T1, T2, T3) GRA {
|
||||
return RE.Eitherize4[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize5]
|
||||
func Eitherize5[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, R any](f F) func(T0, T1, T2, T3, T4) GRA {
|
||||
return RE.Eitherize5[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize6]
|
||||
func Eitherize6[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, R any](f F) func(T0, T1, T2, T3, T4, T5) GRA {
|
||||
return RE.Eitherize6[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize7]
|
||||
func Eitherize7[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) GRA {
|
||||
return RE.Eitherize7[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize8]
|
||||
func Eitherize8[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) GRA {
|
||||
return RE.Eitherize8[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize9]
|
||||
func Eitherize9[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) GRA {
|
||||
return RE.Eitherize9[GRA](f)
|
||||
}
|
||||
|
||||
// Eitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning a [GRA]
|
||||
// The inverse function is [Uneitherize10]
|
||||
func Eitherize10[GRA ~func(context.Context) GIOA, F ~func(context.Context, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) GRA {
|
||||
return RE.Eitherize10[GRA](f)
|
||||
}
|
464
context/readerioeither/generic/reader.go
Normal file
464
context/readerioeither/generic/reader.go
Normal file
@ -0,0 +1,464 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
ER "github.com/ibm/fp-go/errors"
|
||||
F "github.com/ibm/fp-go/function"
|
||||
IO "github.com/ibm/fp-go/io/generic"
|
||||
IOE "github.com/ibm/fp-go/ioeither/generic"
|
||||
O "github.com/ibm/fp-go/option"
|
||||
RIE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
func FromEither[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](e E.Either[error, A]) GRA {
|
||||
return RIE.FromEither[GRA](e)
|
||||
}
|
||||
|
||||
func RightReader[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GR ~func(context.Context) A,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](r GR) GRA {
|
||||
return RIE.RightReader[GR, GRA](r)
|
||||
}
|
||||
|
||||
func LeftReader[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GR ~func(context.Context) error,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](l GR) GRA {
|
||||
return RIE.LeftReader[GR, GRA](l)
|
||||
}
|
||||
|
||||
func Left[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](l error) GRA {
|
||||
return RIE.Left[GRA](l)
|
||||
}
|
||||
|
||||
func Right[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](r A) GRA {
|
||||
return RIE.Right[GRA](r)
|
||||
}
|
||||
|
||||
func FromReader[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GR ~func(context.Context) A,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](r GR) GRA {
|
||||
return RIE.FromReader[GR, GRA](r)
|
||||
}
|
||||
|
||||
func MonadMap[
|
||||
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, f func(A) B) GRB {
|
||||
return RIE.MonadMap[GRA, GRB](fa, f)
|
||||
}
|
||||
|
||||
func Map[
|
||||
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](f func(A) B) func(GRA) GRB {
|
||||
return RIE.Map[GRA, GRB](f)
|
||||
}
|
||||
|
||||
func MonadChain[
|
||||
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](ma GRA, f func(A) GRB) GRB {
|
||||
return RIE.MonadChain(ma, f)
|
||||
}
|
||||
|
||||
func Chain[
|
||||
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](f func(A) GRB) func(GRA) GRB {
|
||||
return RIE.Chain[GRA](f)
|
||||
}
|
||||
|
||||
func MonadChainFirst[
|
||||
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](ma GRA, f func(A) GRB) GRA {
|
||||
return RIE.MonadChainFirst(ma, f)
|
||||
}
|
||||
|
||||
func ChainFirst[
|
||||
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](f func(A) GRB) func(GRA) GRA {
|
||||
return RIE.ChainFirst[GRA](f)
|
||||
}
|
||||
|
||||
func Of[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](a A) GRA {
|
||||
return RIE.Of[GRA](a)
|
||||
}
|
||||
|
||||
// withCancelCauseFunc wraps an IOEither such that in case of an error the cancel function is invoked
|
||||
func withCancelCauseFunc[
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](cancel context.CancelCauseFunc, ma GIOA) GIOA {
|
||||
return F.Pipe3(
|
||||
ma,
|
||||
IOE.Swap[GIOA, func() E.Either[A, error]],
|
||||
IOE.ChainFirstIOK[func() E.Either[A, error], func() any](func(err error) func() any {
|
||||
return IO.MakeIO[func() any](func() any {
|
||||
cancel(err)
|
||||
return nil
|
||||
})
|
||||
}),
|
||||
IOE.Swap[func() E.Either[A, error], GIOA],
|
||||
)
|
||||
}
|
||||
|
||||
// MonadAp implements the `Ap` function for a reader with context. It creates a sub-context that will
|
||||
// be canceled if any of the input operations errors out or
|
||||
func MonadAp[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRAB ~func(context.Context) GIOAB,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
GIOAB ~func() E.Either[error, func(A) B],
|
||||
|
||||
A, B any](fab GRAB, fa GRA) GRB {
|
||||
// context sensitive input
|
||||
cfab := WithContext(fab)
|
||||
cfa := WithContext(fa)
|
||||
|
||||
return func(ctx context.Context) GIOB {
|
||||
// quick check for cancellation
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return IOE.Left[GIOB](err)
|
||||
}
|
||||
|
||||
return func() E.Either[error, B] {
|
||||
// quick check for cancellation
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return E.Left[B](err)
|
||||
}
|
||||
|
||||
// create sub-contexts for fa and fab, so they can cancel one other
|
||||
ctxSub, cancelSub := context.WithCancelCause(ctx)
|
||||
defer cancelSub(nil) // cancel has to be called in all paths
|
||||
|
||||
fabIOE := withCancelCauseFunc(cancelSub, cfab(ctxSub))
|
||||
faIOE := withCancelCauseFunc(cancelSub, cfa(ctxSub))
|
||||
|
||||
return IOE.MonadAp[GIOA, GIOB, GIOAB](fabIOE, faIOE)()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Ap[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRAB ~func(context.Context) GIOAB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
GIOAB ~func() E.Either[error, func(A) B],
|
||||
|
||||
A, B any](fa GRA) func(GRAB) GRB {
|
||||
return F.Bind2nd(MonadAp[GRB, GRA, GRAB], fa)
|
||||
}
|
||||
|
||||
func FromPredicate[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](pred func(A) bool, onFalse func(A) error) func(A) GRA {
|
||||
return RIE.FromPredicate[GRA](pred, onFalse)
|
||||
}
|
||||
|
||||
func Fold[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() B,
|
||||
|
||||
A, B any](onLeft func(error) GRB, onRight func(A) GRB) func(GRA) GRB {
|
||||
return RIE.Fold[GRB, GRA](onLeft, onRight)
|
||||
}
|
||||
|
||||
func GetOrElse[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
GIOB ~func() A,
|
||||
|
||||
A any](onLeft func(error) GRB) func(GRA) GRB {
|
||||
return RIE.GetOrElse[GRB, GRA](onLeft)
|
||||
}
|
||||
|
||||
func OrElse[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](onLeft func(error) GRA) func(GRA) GRA {
|
||||
return RIE.OrElse[GRA](onLeft)
|
||||
}
|
||||
|
||||
func OrLeft[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
GIOB ~func() error,
|
||||
|
||||
A any](onLeft func(error) GRB) func(GRA) GRA {
|
||||
return RIE.OrLeft[GRA, GRB, GRA](onLeft)
|
||||
}
|
||||
|
||||
func Ask[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, context.Context],
|
||||
|
||||
]() GRA {
|
||||
return RIE.Ask[GRA]()
|
||||
}
|
||||
|
||||
func Asks[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) A,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](r GRB) GRA {
|
||||
|
||||
return RIE.Asks[GRB, GRA](r)
|
||||
}
|
||||
|
||||
func MonadChainEitherK[
|
||||
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](ma GRA, f func(A) E.Either[error, B]) GRB {
|
||||
return RIE.MonadChainEitherK[GRA, GRB](ma, f)
|
||||
}
|
||||
|
||||
func ChainEitherK[
|
||||
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](f func(A) E.Either[error, B]) func(ma GRA) GRB {
|
||||
return RIE.ChainEitherK[GRA, GRB](f)
|
||||
}
|
||||
|
||||
func MonadChainFirstEitherK[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A, B any](ma GRA, f func(A) E.Either[error, B]) GRA {
|
||||
return RIE.MonadChainFirstEitherK[GRA](ma, f)
|
||||
}
|
||||
|
||||
func ChainFirstEitherK[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A, B any](f func(A) E.Either[error, B]) func(ma GRA) GRA {
|
||||
return RIE.ChainFirstEitherK[GRA](f)
|
||||
}
|
||||
|
||||
func ChainOptionK[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
|
||||
GIOB ~func() E.Either[error, B],
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A, B any](onNone func() error) func(func(A) O.Option[B]) func(GRA) GRB {
|
||||
return RIE.ChainOptionK[GRA, GRB](onNone)
|
||||
}
|
||||
|
||||
func FromIOEither[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](t GIOA) GRA {
|
||||
return RIE.FromIOEither[GRA](t)
|
||||
}
|
||||
|
||||
func FromIO[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
GIOB ~func() A,
|
||||
|
||||
A any](t GIOB) GRA {
|
||||
return RIE.FromIO[GRA](t)
|
||||
}
|
||||
|
||||
// Never returns a 'ReaderIOEither' that never returns, except if its context gets canceled
|
||||
func Never[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any]() GRA {
|
||||
return func(ctx context.Context) GIOA {
|
||||
return IOE.MakeIO(func() E.Either[error, A] {
|
||||
<-ctx.Done()
|
||||
return E.Left[A](context.Cause(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func MonadChainIOK[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
GIOB ~func() E.Either[error, B],
|
||||
|
||||
GIO ~func() B,
|
||||
|
||||
A, B any](ma GRA, f func(A) GIO) GRB {
|
||||
return RIE.MonadChainIOK[GRA, GRB](ma, f)
|
||||
}
|
||||
|
||||
func ChainIOK[
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
GIOB ~func() E.Either[error, B],
|
||||
|
||||
GIO ~func() B,
|
||||
|
||||
A, B any](f func(A) GIO) func(ma GRA) GRB {
|
||||
return RIE.ChainIOK[GRA, GRB](f)
|
||||
}
|
||||
|
||||
func MonadChainFirstIOK[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
GIO ~func() B,
|
||||
|
||||
A, B any](ma GRA, f func(A) GIO) GRA {
|
||||
return RIE.MonadChainFirstIOK[GRA](ma, f)
|
||||
}
|
||||
|
||||
func ChainFirstIOK[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
GIO ~func() B,
|
||||
|
||||
A, B any](f func(A) GIO) func(ma GRA) GRA {
|
||||
return RIE.ChainFirstIOK[GRA](f)
|
||||
}
|
||||
|
||||
func ChainIOEitherK[
|
||||
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](f func(A) GIOB) func(ma GRA) GRB {
|
||||
return RIE.ChainIOEitherK[GRA, GRB](f)
|
||||
}
|
||||
|
||||
// Delay creates an operation that passes in the value after some delay
|
||||
func Delay[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](delay time.Duration) func(ma GRA) GRA {
|
||||
return func(ma GRA) GRA {
|
||||
return func(ctx context.Context) GIOA {
|
||||
return IOE.MakeIO(func() E.Either[error, A] {
|
||||
// manage the timeout
|
||||
timeoutCtx, cancelTimeout := context.WithTimeout(ctx, delay)
|
||||
defer cancelTimeout()
|
||||
// whatever comes first
|
||||
select {
|
||||
case <-timeoutCtx.Done():
|
||||
return ma(ctx)()
|
||||
case <-ctx.Done():
|
||||
return E.Left[A](context.Cause(ctx))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Timer will return the current time after an initial delay
|
||||
func Timer[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, time.Time],
|
||||
|
||||
](delay time.Duration) GRA {
|
||||
return F.Pipe2(
|
||||
IO.Now[func() time.Time](),
|
||||
FromIO[GRA, GIOA, func() time.Time],
|
||||
Delay[GRA](delay),
|
||||
)
|
||||
}
|
||||
|
||||
// Defer creates an IO by creating a brand new IO via a generator function, each time
|
||||
func Defer[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](gen func() GRA) GRA {
|
||||
return RIE.Defer[GRA](gen)
|
||||
}
|
||||
|
||||
// TryCatch wraps a reader returning a tuple as an error into ReaderIOEither
|
||||
func TryCatch[
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOA ~func() E.Either[error, A],
|
||||
|
||||
A any](f func(context.Context) func() (A, error)) GRA {
|
||||
return RIE.TryCatch[GRA](f, ER.IdentityError)
|
||||
}
|
25
context/readerioeither/generic/resource.go
Normal file
25
context/readerioeither/generic/resource.go
Normal file
@ -0,0 +1,25 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
F "github.com/ibm/fp-go/function"
|
||||
RIE "github.com/ibm/fp-go/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),
|
||||
)
|
||||
}
|
85
context/readerioeither/generic/sequence.go
Normal file
85
context/readerioeither/generic/sequence.go
Normal file
@ -0,0 +1,85 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
T "github.com/ibm/fp-go/tuple"
|
||||
)
|
||||
|
||||
// SequenceT converts n inputs of higher kinded types into a higher kinded types of n strongly typed values, represented as a tuple
|
||||
|
||||
func SequenceT1[
|
||||
GRT ~func(context.Context) GIOT,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOT ~func() E.Either[error, T.Tuple1[A]],
|
||||
|
||||
A any](a GRA) GRT {
|
||||
return RE.SequenceT1[
|
||||
GRA,
|
||||
GRT,
|
||||
](a)
|
||||
}
|
||||
|
||||
func SequenceT2[
|
||||
GRT ~func(context.Context) GIOT,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
GIOT ~func() E.Either[error, T.Tuple2[A, B]],
|
||||
|
||||
A, B any](a GRA, b GRB) GRT {
|
||||
return RE.SequenceT2[
|
||||
GRA,
|
||||
GRB,
|
||||
GRT,
|
||||
](a, b)
|
||||
}
|
||||
|
||||
func SequenceT3[
|
||||
GRT ~func(context.Context) GIOT,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRC ~func(context.Context) GIOC,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
GIOC ~func() E.Either[error, C],
|
||||
GIOT ~func() E.Either[error, T.Tuple3[A, B, C]],
|
||||
|
||||
A, B, C any](a GRA, b GRB, c GRC) GRT {
|
||||
return RE.SequenceT3[
|
||||
GRA,
|
||||
GRB,
|
||||
GRC,
|
||||
GRT,
|
||||
](a, b, c)
|
||||
}
|
||||
|
||||
func SequenceT4[
|
||||
GRT ~func(context.Context) GIOT,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GRC ~func(context.Context) GIOC,
|
||||
GRD ~func(context.Context) GIOD,
|
||||
|
||||
GIOA ~func() E.Either[error, A],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
GIOC ~func() E.Either[error, C],
|
||||
GIOD ~func() E.Either[error, D],
|
||||
GIOT ~func() E.Either[error, T.Tuple4[A, B, C, D]],
|
||||
|
||||
A, B, C, D any](a GRA, b GRB, c GRC, d GRD) GRT {
|
||||
return RE.SequenceT4[
|
||||
GRA,
|
||||
GRB,
|
||||
GRC,
|
||||
GRD,
|
||||
GRT,
|
||||
](a, b, c, d)
|
||||
}
|
57
context/readerioeither/generic/traverse.go
Normal file
57
context/readerioeither/generic/traverse.go
Normal file
@ -0,0 +1,57 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/ibm/fp-go/either"
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// TraverseArray transforms an array
|
||||
func TraverseArray[
|
||||
AS ~[]A,
|
||||
GRBS ~func(context.Context) GIOBS,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GIOBS ~func() E.Either[error, BS],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
BS ~[]B,
|
||||
A, B any](f func(A) GRB) func(AS) GRBS {
|
||||
return RE.TraverseArray[GRB, GRBS, GIOB, GIOBS, AS](f)
|
||||
}
|
||||
|
||||
// SequenceArray converts a homogeneous sequence of either into an either of sequence
|
||||
func SequenceArray[
|
||||
AS ~[]A,
|
||||
GAS ~[]GRA,
|
||||
GRAS ~func(context.Context) GIOAS,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOAS ~func() E.Either[error, AS],
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](ma GAS) GRAS {
|
||||
return RE.SequenceArray[GRA, GRAS](ma)
|
||||
}
|
||||
|
||||
// TraverseRecord transforms a record
|
||||
func TraverseRecord[K comparable,
|
||||
AS ~map[K]A,
|
||||
GRBS ~func(context.Context) GIOBS,
|
||||
GRB ~func(context.Context) GIOB,
|
||||
GIOBS ~func() E.Either[error, BS],
|
||||
GIOB ~func() E.Either[error, B],
|
||||
BS ~map[K]B,
|
||||
|
||||
A, B any](f func(A) GRB) func(AS) GRBS {
|
||||
return RE.TraverseRecord[GRB, GRBS, GIOB, GIOBS, AS](f)
|
||||
}
|
||||
|
||||
// SequenceRecord converts a homogeneous sequence of either into an either of sequence
|
||||
func SequenceRecord[K comparable,
|
||||
AS ~map[K]A,
|
||||
GAS ~map[K]GRA,
|
||||
GRAS ~func(context.Context) GIOAS,
|
||||
GRA ~func(context.Context) GIOA,
|
||||
GIOAS ~func() E.Either[error, AS],
|
||||
GIOA ~func() E.Either[error, A],
|
||||
A any](ma GAS) GRAS {
|
||||
return RE.SequenceRecord[GRA, GRAS](ma)
|
||||
}
|
@ -71,21 +71,6 @@ func ReadFullResponse(client Client) func(Requester) RIOE.ReaderIOEither[H.FullR
|
||||
}
|
||||
}
|
||||
|
||||
// func test(resp *http.Response) IOE.IOEither[error, H.FullResponse] {
|
||||
// x := F.Pipe3(
|
||||
// resp,
|
||||
// T.Replicate2[*http.Response],
|
||||
// T.Map2(
|
||||
// IOE.Of[error, *http.Response],
|
||||
// F.Flow3(
|
||||
// H.GetBody,
|
||||
// IOE.Of[error, io.ReadCloser],
|
||||
// IOEF.ReadAll[io.ReadCloser],
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// }
|
||||
|
||||
// ReadAll sends a request and reads the response as bytes
|
||||
func ReadAll(client Client) func(Requester) RIOE.ReaderIOEither[[]byte] {
|
||||
return F.Flow2(
|
||||
|
@ -6,238 +6,172 @@ import (
|
||||
|
||||
R "github.com/ibm/fp-go/context/reader"
|
||||
RIO "github.com/ibm/fp-go/context/readerio"
|
||||
G "github.com/ibm/fp-go/context/readerioeither/generic"
|
||||
ET "github.com/ibm/fp-go/either"
|
||||
ER "github.com/ibm/fp-go/errors"
|
||||
F "github.com/ibm/fp-go/function"
|
||||
IO "github.com/ibm/fp-go/io"
|
||||
IOE "github.com/ibm/fp-go/ioeither"
|
||||
O "github.com/ibm/fp-go/option"
|
||||
RIE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
func FromEither[A any](e ET.Either[error, A]) ReaderIOEither[A] {
|
||||
return RIE.FromEither[ReaderIOEither[A]](e)
|
||||
return G.FromEither[ReaderIOEither[A]](e)
|
||||
}
|
||||
|
||||
func RightReader[A any](r R.Reader[A]) ReaderIOEither[A] {
|
||||
return RIE.RightReader[R.Reader[A], ReaderIOEither[A]](r)
|
||||
return G.RightReader[ReaderIOEither[A]](r)
|
||||
}
|
||||
|
||||
func LeftReader[A any](l R.Reader[error]) ReaderIOEither[A] {
|
||||
return RIE.LeftReader[R.Reader[error], ReaderIOEither[A]](l)
|
||||
return G.LeftReader[ReaderIOEither[A]](l)
|
||||
}
|
||||
|
||||
func Left[A any](l error) ReaderIOEither[A] {
|
||||
return RIE.Left[ReaderIOEither[A]](l)
|
||||
return G.Left[ReaderIOEither[A]](l)
|
||||
}
|
||||
|
||||
func Right[A any](r A) ReaderIOEither[A] {
|
||||
return RIE.Right[ReaderIOEither[A]](r)
|
||||
return G.Right[ReaderIOEither[A]](r)
|
||||
}
|
||||
|
||||
func FromReader[A any](r R.Reader[A]) ReaderIOEither[A] {
|
||||
return RIE.FromReader[R.Reader[A], ReaderIOEither[A]](r)
|
||||
return G.FromReader[ReaderIOEither[A]](r)
|
||||
}
|
||||
|
||||
func MonadMap[A, B any](fa ReaderIOEither[A], f func(A) B) ReaderIOEither[B] {
|
||||
return RIE.MonadMap[ReaderIOEither[A], ReaderIOEither[B]](fa, f)
|
||||
return G.MonadMap[ReaderIOEither[A], ReaderIOEither[B]](fa, f)
|
||||
}
|
||||
|
||||
func Map[A, B any](f func(A) B) func(ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return RIE.Map[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
return G.Map[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
}
|
||||
|
||||
func MonadChain[A, B any](ma ReaderIOEither[A], f func(A) ReaderIOEither[B]) ReaderIOEither[B] {
|
||||
return RIE.MonadChain(ma, f)
|
||||
return G.MonadChain(ma, f)
|
||||
}
|
||||
|
||||
func Chain[A, B any](f func(A) ReaderIOEither[B]) func(ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return RIE.Chain[ReaderIOEither[A]](f)
|
||||
return G.Chain[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func MonadChainFirst[A, B any](ma ReaderIOEither[A], f func(A) ReaderIOEither[B]) ReaderIOEither[A] {
|
||||
return RIE.MonadChainFirst(ma, f)
|
||||
return G.MonadChainFirst(ma, f)
|
||||
}
|
||||
|
||||
func ChainFirst[A, B any](f func(A) ReaderIOEither[B]) func(ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return RIE.ChainFirst[ReaderIOEither[A]](f)
|
||||
return G.ChainFirst[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func Of[A any](a A) ReaderIOEither[A] {
|
||||
return RIE.Of[ReaderIOEither[A]](a)
|
||||
}
|
||||
|
||||
// withCancelCauseFunc wraps an IOEither such that in case of an error the cancel function is invoked
|
||||
func withCancelCauseFunc[A any](cancel context.CancelCauseFunc, ma IOE.IOEither[error, A]) IOE.IOEither[error, A] {
|
||||
return F.Pipe3(
|
||||
ma,
|
||||
IOE.Swap[error, A],
|
||||
IOE.ChainFirstIOK[A, error, any](func(err error) IO.IO[any] {
|
||||
return IO.MakeIO(func() any {
|
||||
cancel(err)
|
||||
return nil
|
||||
})
|
||||
}),
|
||||
IOE.Swap[A, error],
|
||||
)
|
||||
return G.Of[ReaderIOEither[A]](a)
|
||||
}
|
||||
|
||||
// MonadAp implements the `Ap` function for a reader with context. It creates a sub-context that will
|
||||
// be canceled if any of the input operations errors out or
|
||||
func MonadAp[A, B any](fab ReaderIOEither[func(A) B], fa ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
// context sensitive input
|
||||
cfab := WithContext(fab)
|
||||
cfa := WithContext(fa)
|
||||
|
||||
return func(ctx context.Context) IOE.IOEither[error, B] {
|
||||
// quick check for cancellation
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return IOE.Left[B](err)
|
||||
}
|
||||
|
||||
return func() ET.Either[error, B] {
|
||||
// quick check for cancellation
|
||||
if err := context.Cause(ctx); err != nil {
|
||||
return ET.Left[B](err)
|
||||
}
|
||||
|
||||
// create sub-contexts for fa and fab, so they can cancel one other
|
||||
ctxSub, cancelSub := context.WithCancelCause(ctx)
|
||||
defer cancelSub(nil) // cancel has to be called in all paths
|
||||
|
||||
fabIOE := withCancelCauseFunc(cancelSub, cfab(ctxSub))
|
||||
faIOE := withCancelCauseFunc(cancelSub, cfa(ctxSub))
|
||||
|
||||
return IOE.MonadAp(fabIOE, faIOE)()
|
||||
}
|
||||
}
|
||||
func MonadAp[B, A any](fab ReaderIOEither[func(A) B], fa ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return G.MonadAp[ReaderIOEither[B]](fab, fa)
|
||||
}
|
||||
|
||||
func Ap[A, B any](fa ReaderIOEither[A]) func(ReaderIOEither[func(A) B]) ReaderIOEither[B] {
|
||||
return F.Bind2nd(MonadAp[A, B], fa)
|
||||
func Ap[B, A any](fa ReaderIOEither[A]) func(ReaderIOEither[func(A) B]) ReaderIOEither[B] {
|
||||
return G.Ap[ReaderIOEither[B], ReaderIOEither[func(A) B]](fa)
|
||||
}
|
||||
|
||||
func FromPredicate[A any](pred func(A) bool, onFalse func(A) error) func(A) ReaderIOEither[A] {
|
||||
return RIE.FromPredicate[ReaderIOEither[A]](pred, onFalse)
|
||||
return G.FromPredicate[ReaderIOEither[A]](pred, onFalse)
|
||||
}
|
||||
|
||||
func Fold[A, B any](onLeft func(error) RIO.ReaderIO[B], onRight func(A) RIO.ReaderIO[B]) func(ReaderIOEither[A]) RIO.ReaderIO[B] {
|
||||
return RIE.Fold[RIO.ReaderIO[B], ReaderIOEither[A]](onLeft, onRight)
|
||||
return G.Fold[RIO.ReaderIO[B], ReaderIOEither[A]](onLeft, onRight)
|
||||
}
|
||||
|
||||
func GetOrElse[A any](onLeft func(error) RIO.ReaderIO[A]) func(ReaderIOEither[A]) RIO.ReaderIO[A] {
|
||||
return RIE.GetOrElse[RIO.ReaderIO[A], ReaderIOEither[A]](onLeft)
|
||||
return G.GetOrElse[RIO.ReaderIO[A], ReaderIOEither[A]](onLeft)
|
||||
}
|
||||
|
||||
func OrElse[A any](onLeft func(error) ReaderIOEither[A]) func(ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return RIE.OrElse[ReaderIOEither[A]](onLeft)
|
||||
return G.OrElse[ReaderIOEither[A]](onLeft)
|
||||
}
|
||||
|
||||
func OrLeft[A any](onLeft func(error) RIO.ReaderIO[error]) func(ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return RIE.OrLeft[ReaderIOEither[A], RIO.ReaderIO[error], ReaderIOEither[A]](onLeft)
|
||||
return G.OrLeft[ReaderIOEither[A], RIO.ReaderIO[error]](onLeft)
|
||||
}
|
||||
|
||||
func Ask() ReaderIOEither[context.Context] {
|
||||
return RIE.Ask[ReaderIOEither[context.Context]]()
|
||||
return G.Ask[ReaderIOEither[context.Context]]()
|
||||
}
|
||||
|
||||
func Asks[A any](r R.Reader[A]) ReaderIOEither[A] {
|
||||
return RIE.Asks[R.Reader[A], ReaderIOEither[A]](r)
|
||||
return G.Asks[ReaderIOEither[A]](r)
|
||||
}
|
||||
|
||||
func MonadChainEitherK[A, B any](ma ReaderIOEither[A], f func(A) ET.Either[error, B]) ReaderIOEither[B] {
|
||||
return RIE.MonadChainEitherK[ReaderIOEither[A], ReaderIOEither[B]](ma, f)
|
||||
return G.MonadChainEitherK[ReaderIOEither[A], ReaderIOEither[B]](ma, f)
|
||||
}
|
||||
|
||||
func ChainEitherK[A, B any](f func(A) ET.Either[error, B]) func(ma ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return RIE.ChainEitherK[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
return G.ChainEitherK[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
}
|
||||
|
||||
func MonadChainFirstEitherK[A, B any](ma ReaderIOEither[A], f func(A) ET.Either[error, B]) ReaderIOEither[A] {
|
||||
return RIE.MonadChainFirstEitherK[ReaderIOEither[A]](ma, f)
|
||||
return G.MonadChainFirstEitherK[ReaderIOEither[A]](ma, f)
|
||||
}
|
||||
|
||||
func ChainFirstEitherK[A, B any](f func(A) ET.Either[error, B]) func(ma ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return RIE.ChainFirstEitherK[ReaderIOEither[A]](f)
|
||||
return G.ChainFirstEitherK[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func ChainOptionK[A, B any](onNone func() error) func(func(A) O.Option[B]) func(ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return RIE.ChainOptionK[ReaderIOEither[A], ReaderIOEither[B]](onNone)
|
||||
return G.ChainOptionK[ReaderIOEither[A], ReaderIOEither[B]](onNone)
|
||||
}
|
||||
|
||||
func FromIOEither[A any](t IOE.IOEither[error, A]) ReaderIOEither[A] {
|
||||
return RIE.FromIOEither[ReaderIOEither[A]](t)
|
||||
return G.FromIOEither[ReaderIOEither[A]](t)
|
||||
}
|
||||
|
||||
func FromIO[A any](t IO.IO[A]) ReaderIOEither[A] {
|
||||
return RIE.FromIO[ReaderIOEither[A]](t)
|
||||
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 func(ctx context.Context) IOE.IOEither[error, A] {
|
||||
return IOE.MakeIO(func() ET.Either[error, A] {
|
||||
<-ctx.Done()
|
||||
return ET.Left[A](context.Cause(ctx))
|
||||
})
|
||||
}
|
||||
return G.Never[ReaderIOEither[A]]()
|
||||
}
|
||||
|
||||
func MonadChainIOK[A, B any](ma ReaderIOEither[A], f func(A) IO.IO[B]) ReaderIOEither[B] {
|
||||
return RIE.MonadChainIOK[ReaderIOEither[A], ReaderIOEither[B]](ma, f)
|
||||
return G.MonadChainIOK[ReaderIOEither[B], ReaderIOEither[A]](ma, f)
|
||||
}
|
||||
|
||||
func ChainIOK[A, B any](f func(A) IO.IO[B]) func(ma ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return RIE.ChainIOK[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
return G.ChainIOK[ReaderIOEither[B], ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func MonadChainFirstIOK[A, B any](ma ReaderIOEither[A], f func(A) IO.IO[B]) ReaderIOEither[A] {
|
||||
return RIE.MonadChainFirstIOK[ReaderIOEither[A]](ma, f)
|
||||
return G.MonadChainFirstIOK[ReaderIOEither[A]](ma, f)
|
||||
}
|
||||
|
||||
func ChainFirstIOK[A, B any](f func(A) IO.IO[B]) func(ma ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return RIE.ChainFirstIOK[ReaderIOEither[A]](f)
|
||||
return G.ChainFirstIOK[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
||||
func ChainIOEitherK[A, B any](f func(A) IOE.IOEither[error, B]) func(ma ReaderIOEither[A]) ReaderIOEither[B] {
|
||||
return RIE.ChainIOEitherK[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
return G.ChainIOEitherK[ReaderIOEither[A], ReaderIOEither[B]](f)
|
||||
}
|
||||
|
||||
// Delay creates an operation that passes in the value after some delay
|
||||
func Delay[A any](delay time.Duration) func(ma ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return func(ma ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return func(ctx context.Context) IOE.IOEither[error, A] {
|
||||
return IOE.MakeIO(func() ET.Either[error, A] {
|
||||
// manage the timeout
|
||||
timeoutCtx, cancelTimeout := context.WithTimeout(ctx, delay)
|
||||
defer cancelTimeout()
|
||||
// whatever comes first
|
||||
select {
|
||||
case <-timeoutCtx.Done():
|
||||
return ma(ctx)()
|
||||
case <-ctx.Done():
|
||||
return ET.Left[A](context.Cause(ctx))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return G.Delay[ReaderIOEither[A]](delay)
|
||||
}
|
||||
|
||||
// Timer will return the current time after an initial delay
|
||||
func Timer(delay time.Duration) ReaderIOEither[time.Time] {
|
||||
return F.Pipe2(
|
||||
IO.Now,
|
||||
FromIO[time.Time],
|
||||
Delay[time.Time](delay),
|
||||
)
|
||||
return G.Timer[ReaderIOEither[time.Time]](delay)
|
||||
}
|
||||
|
||||
// Defer creates an IO by creating a brand new IO via a generator function, each time
|
||||
func Defer[A any](gen func() ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
return RIE.Defer[ReaderIOEither[A]](gen)
|
||||
return G.Defer[ReaderIOEither[A]](gen)
|
||||
}
|
||||
|
||||
// TryCatch wraps a reader returning a tuple as an error into ReaderIOEither
|
||||
func TryCatch[A any](f func(context.Context) func() (A, error)) ReaderIOEither[A] {
|
||||
return RIE.TryCatch[ReaderIOEither[A]](f, ER.IdentityError)
|
||||
return G.TryCatch[ReaderIOEither[A]](f)
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
package readerioeither
|
||||
|
||||
import (
|
||||
F "github.com/ibm/fp-go/function"
|
||||
RIE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
G "github.com/ibm/fp-go/context/readerioeither/generic"
|
||||
)
|
||||
|
||||
// WithResource constructs a function that creates a resource, then operates on it and then releases the resource
|
||||
func WithResource[R, A any](onCreate ReaderIOEither[R], onRelease func(R) ReaderIOEither[any]) func(func(R) ReaderIOEither[A]) ReaderIOEither[A] {
|
||||
func WithResource[R, A, 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 F.Flow2(
|
||||
F.Bind2nd(F.Flow2[func(R) ReaderIOEither[A], func(ReaderIOEither[A]) ReaderIOEither[A], R, ReaderIOEither[A], ReaderIOEither[A]], WithContext[A]),
|
||||
RIE.WithResource[ReaderIOEither[A]](WithContext(onCreate), onRelease),
|
||||
)
|
||||
return G.WithResource[ReaderIOEither[A]](onCreate, onRelease)
|
||||
}
|
||||
|
@ -1,42 +1,24 @@
|
||||
package readerioeither
|
||||
|
||||
import (
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
G "github.com/ibm/fp-go/context/readerioeither/generic"
|
||||
T "github.com/ibm/fp-go/tuple"
|
||||
)
|
||||
|
||||
// SequenceT converts n inputs of higher kinded types into a higher kinded types of n strongly typed values, represented as a tuple
|
||||
|
||||
func SequenceT1[A any](a ReaderIOEither[A]) ReaderIOEither[T.Tuple1[A]] {
|
||||
return RE.SequenceT1[
|
||||
ReaderIOEither[A],
|
||||
ReaderIOEither[T.Tuple1[A]],
|
||||
](a)
|
||||
return G.SequenceT1[ReaderIOEither[T.Tuple1[A]]](a)
|
||||
}
|
||||
|
||||
func SequenceT2[A, B any](a ReaderIOEither[A], b ReaderIOEither[B]) ReaderIOEither[T.Tuple2[A, B]] {
|
||||
return RE.SequenceT2[
|
||||
ReaderIOEither[A],
|
||||
ReaderIOEither[B],
|
||||
ReaderIOEither[T.Tuple2[A, B]],
|
||||
](a, b)
|
||||
return G.SequenceT2[ReaderIOEither[T.Tuple2[A, B]]](a, b)
|
||||
}
|
||||
|
||||
func SequenceT3[A, B, C any](a ReaderIOEither[A], b ReaderIOEither[B], c ReaderIOEither[C]) ReaderIOEither[T.Tuple3[A, B, C]] {
|
||||
return RE.SequenceT3[
|
||||
ReaderIOEither[A],
|
||||
ReaderIOEither[B],
|
||||
ReaderIOEither[C],
|
||||
ReaderIOEither[T.Tuple3[A, B, C]],
|
||||
](a, b, c)
|
||||
return G.SequenceT3[ReaderIOEither[T.Tuple3[A, B, C]]](a, b, c)
|
||||
}
|
||||
|
||||
func SequenceT4[A, B, C, D any](a ReaderIOEither[A], b ReaderIOEither[B], c ReaderIOEither[C], d ReaderIOEither[D]) ReaderIOEither[T.Tuple4[A, B, C, D]] {
|
||||
return RE.SequenceT4[
|
||||
ReaderIOEither[A],
|
||||
ReaderIOEither[B],
|
||||
ReaderIOEither[C],
|
||||
ReaderIOEither[D],
|
||||
ReaderIOEither[T.Tuple4[A, B, C, D]],
|
||||
](a, b, c, d)
|
||||
return G.SequenceT4[ReaderIOEither[T.Tuple4[A, B, C, D]]](a, b, c, d)
|
||||
}
|
||||
|
@ -1,26 +1,25 @@
|
||||
package readerioeither
|
||||
|
||||
import (
|
||||
IOE "github.com/ibm/fp-go/ioeither"
|
||||
RE "github.com/ibm/fp-go/readerioeither/generic"
|
||||
G "github.com/ibm/fp-go/context/readerioeither/generic"
|
||||
)
|
||||
|
||||
// TraverseArray transforms an array
|
||||
func TraverseArray[A, B any](f func(A) ReaderIOEither[B]) func([]A) ReaderIOEither[[]B] {
|
||||
return RE.TraverseArray[ReaderIOEither[B], ReaderIOEither[[]B], IOE.IOEither[error, B], IOE.IOEither[error, []B], []A](f)
|
||||
return G.TraverseArray[[]A, ReaderIOEither[[]B]](f)
|
||||
}
|
||||
|
||||
// SequenceArray converts a homogeneous sequence of either into an either of sequence
|
||||
func SequenceArray[A any](ma []ReaderIOEither[A]) ReaderIOEither[[]A] {
|
||||
return RE.SequenceArray[ReaderIOEither[A], ReaderIOEither[[]A]](ma)
|
||||
return G.SequenceArray[[]A, []ReaderIOEither[A], ReaderIOEither[[]A]](ma)
|
||||
}
|
||||
|
||||
// TraverseRecord transforms a record
|
||||
func TraverseRecord[K comparable, A, B any](f func(A) ReaderIOEither[B]) func(map[K]A) ReaderIOEither[map[K]B] {
|
||||
return RE.TraverseRecord[ReaderIOEither[B], ReaderIOEither[map[K]B], IOE.IOEither[error, B], IOE.IOEither[error, map[K]B], map[K]A](f)
|
||||
return G.TraverseRecord[K, map[K]A, ReaderIOEither[map[K]B]](f)
|
||||
}
|
||||
|
||||
// SequenceRecord converts a homogeneous sequence of either into an either of sequence
|
||||
func SequenceRecord[K comparable, A any](ma map[K]ReaderIOEither[A]) ReaderIOEither[map[K]A] {
|
||||
return RE.SequenceRecord[ReaderIOEither[A], ReaderIOEither[map[K]A]](ma)
|
||||
return G.SequenceRecord[K, map[K]A, map[K]ReaderIOEither[A], ReaderIOEither[map[K]A]](ma)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-17 17:35:30.8817939 +0200 CEST m=+0.036907301
|
||||
// 2023-07-18 15:21:17.0339772 +0200 CEST m=+0.084638001
|
||||
package either
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-17 17:35:52.0895848 +0200 CEST m=+0.125356601
|
||||
// 2023-07-18 15:21:26.5345454 +0200 CEST m=+0.141115301
|
||||
package function
|
||||
// Combinations for a total of 1 arguments
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-17 17:35:38.6832268 +0200 CEST m=+0.043674901
|
||||
// 2023-07-18 15:21:22.6104564 +0200 CEST m=+0.036231301
|
||||
package function
|
||||
|
||||
// Pipe0 takes an initial value t0 and successively applies 0 functions where the input of a function is the return value of the previous function
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-17 17:36:02.7073931 +0200 CEST m=+0.136048201
|
||||
// 2023-07-18 15:21:31.1196366 +0200 CEST m=+0.033039101
|
||||
package identity
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-17 17:36:29.7966147 +0200 CEST m=+0.102380501
|
||||
// 2023-07-18 15:21:34.1598359 +0200 CEST m=+0.018814001
|
||||
package apply
|
||||
|
||||
|
||||
|
@ -1,3 +1,18 @@
|
||||
// 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 exec
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,18 @@
|
||||
// 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 exec
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,18 @@
|
||||
// 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 magma
|
||||
|
||||
import (
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-17 17:36:37.8185556 +0200 CEST m=+0.131678801
|
||||
// 2023-07-18 15:21:38.0536143 +0200 CEST m=+0.141220201
|
||||
package option
|
||||
|
||||
|
||||
|
@ -1,3 +1,18 @@
|
||||
// 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 number
|
||||
|
||||
import (
|
||||
|
3
reader/doc.go
Normal file
3
reader/doc.go
Normal file
@ -0,0 +1,3 @@
|
||||
package reader
|
||||
|
||||
//go:generate go run .. reader --count 10 --filename gen.go
|
@ -1,25 +0,0 @@
|
||||
package reader
|
||||
|
||||
import (
|
||||
G "github.com/ibm/fp-go/reader/generic"
|
||||
)
|
||||
|
||||
func From0[R, A any](f func(R) A) Reader[R, A] {
|
||||
return G.From0[Reader[R, A]](f)
|
||||
}
|
||||
|
||||
func From1[R, T1, A any](f func(R, T1) A) func(T1) Reader[R, A] {
|
||||
return G.From1[Reader[R, A]](f)
|
||||
}
|
||||
|
||||
func From2[R, T1, T2, A any](f func(R, T1, T2) A) func(T1, T2) Reader[R, A] {
|
||||
return G.From2[Reader[R, A]](f)
|
||||
}
|
||||
|
||||
func From3[R, T1, T2, T3, A any](f func(R, T1, T2, T3) A) func(T1, T2, T3) Reader[R, A] {
|
||||
return G.From3[Reader[R, A]](f)
|
||||
}
|
||||
|
||||
func From4[R, T1, T2, T3, T4, A any](f func(R, T1, T2, T3, T4) A) func(T1, T2, T3, T4) Reader[R, A] {
|
||||
return G.From4[Reader[R, A]](f)
|
||||
}
|
75
reader/gen.go
Normal file
75
reader/gen.go
Normal file
@ -0,0 +1,75 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-18 15:21:41.9222583 +0200 CEST m=+0.026140101
|
||||
package reader
|
||||
|
||||
|
||||
import (
|
||||
G "github.com/ibm/fp-go/reader/generic"
|
||||
)
|
||||
|
||||
// From0 converts a function with 1 parameters returning a [R] into a function with 0 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From0[F ~func(C) R, C, R any](f F) func() Reader[C, R] {
|
||||
return G.From0[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From1 converts a function with 2 parameters returning a [R] into a function with 1 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From1[F ~func(C, T0) R, T0, C, R any](f F) func(T0) Reader[C, R] {
|
||||
return G.From1[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From2 converts a function with 3 parameters returning a [R] into a function with 2 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From2[F ~func(C, T0, T1) R, T0, T1, C, R any](f F) func(T0, T1) Reader[C, R] {
|
||||
return G.From2[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From3 converts a function with 4 parameters returning a [R] into a function with 3 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From3[F ~func(C, T0, T1, T2) R, T0, T1, T2, C, R any](f F) func(T0, T1, T2) Reader[C, R] {
|
||||
return G.From3[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From4 converts a function with 5 parameters returning a [R] into a function with 4 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From4[F ~func(C, T0, T1, T2, T3) R, T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) Reader[C, R] {
|
||||
return G.From4[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From5 converts a function with 6 parameters returning a [R] into a function with 5 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From5[F ~func(C, T0, T1, T2, T3, T4) R, T0, T1, T2, T3, T4, C, R any](f F) func(T0, T1, T2, T3, T4) Reader[C, R] {
|
||||
return G.From5[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From6 converts a function with 7 parameters returning a [R] into a function with 6 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From6[F ~func(C, T0, T1, T2, T3, T4, T5) R, T0, T1, T2, T3, T4, T5, C, R any](f F) func(T0, T1, T2, T3, T4, T5) Reader[C, R] {
|
||||
return G.From6[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From7 converts a function with 8 parameters returning a [R] into a function with 7 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From7[F ~func(C, T0, T1, T2, T3, T4, T5, T6) R, T0, T1, T2, T3, T4, T5, T6, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) Reader[C, R] {
|
||||
return G.From7[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From8 converts a function with 9 parameters returning a [R] into a function with 8 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From8[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) R, T0, T1, T2, T3, T4, T5, T6, T7, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) Reader[C, R] {
|
||||
return G.From8[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From9 converts a function with 10 parameters returning a [R] into a function with 9 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From9[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) 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) Reader[C, R] {
|
||||
return G.From9[Reader[C, R]](f)
|
||||
}
|
||||
|
||||
// From10 converts a function with 11 parameters returning a [R] into a function with 10 parameters returning a [Reader[C, R]]
|
||||
// The first parameter is considered to be the context [C] of the reader
|
||||
func From10[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) 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) Reader[C, R] {
|
||||
return G.From10[Reader[C, R]](f)
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package generic
|
||||
|
||||
// these functions convert a golang function with the context as the first parameter into a reader with the context as the last parameter, which
|
||||
// is a equivalent to a function returning a reader of that context
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[GA ~func(R) A, R, A any](f func(R) A) GA {
|
||||
return MakeReader[GA](f)
|
||||
}
|
||||
|
||||
func From1[GA ~func(R) A, R, T1, A any](f func(R, T1) A) func(T1) GA {
|
||||
return func(t1 T1) GA {
|
||||
return MakeReader[GA](func(r R) A {
|
||||
return f(r, t1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func From2[GA ~func(R) A, R, T1, T2, A any](f func(R, T1, T2) A) func(T1, T2) GA {
|
||||
return func(t1 T1, t2 T2) GA {
|
||||
return MakeReader[GA](func(r R) A {
|
||||
return f(r, t1, t2)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func From3[GA ~func(R) A, R, T1, T2, T3, A any](f func(R, T1, T2, T3) A) func(T1, T2, T3) GA {
|
||||
return func(t1 T1, t2 T2, t3 T3) GA {
|
||||
return MakeReader[GA](func(r R) A {
|
||||
return f(r, t1, t2, t3)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func From4[GA ~func(R) A, R, T1, T2, T3, T4, A any](f func(R, T1, T2, T3, T4) A) func(T1, T2, T3, T4) GA {
|
||||
return func(t1 T1, t2 T2, t3 T3, t4 T4) GA {
|
||||
return MakeReader[GA](func(r R) A {
|
||||
return f(r, t1, t2, t3, t4)
|
||||
})
|
||||
}
|
||||
}
|
115
reader/generic/gen.go
Normal file
115
reader/generic/gen.go
Normal file
@ -0,0 +1,115 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-18 15:21:41.9222583 +0200 CEST m=+0.026140101
|
||||
package generic
|
||||
|
||||
|
||||
// From0 converts a function with 1 parameters returning a [R] into a function with 0 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From0[GRA ~func(C) R, F ~func(C) R, C, R any](f F) func() GRA {
|
||||
return func() GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From1 converts a function with 2 parameters returning a [R] into a function with 1 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From1[GRA ~func(C) R, F ~func(C, T0) R, T0, C, R any](f F) func(T0) GRA {
|
||||
return func(t0 T0) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From2 converts a function with 3 parameters returning a [R] into a function with 2 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From2[GRA ~func(C) R, F ~func(C, T0, T1) R, T0, T1, C, R any](f F) func(T0, T1) GRA {
|
||||
return func(t0 T0, t1 T1) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From3 converts a function with 4 parameters returning a [R] into a function with 3 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From3[GRA ~func(C) R, F ~func(C, T0, T1, T2) R, T0, T1, T2, C, R any](f F) func(T0, T1, T2) GRA {
|
||||
return func(t0 T0, t1 T1, t2 T2) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From4 converts a function with 5 parameters returning a [R] into a function with 4 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From4[GRA ~func(C) R, F ~func(C, T0, T1, T2, T3) R, T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) GRA {
|
||||
return func(t0 T0, t1 T1, t2 T2, t3 T3) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2, t3)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From5 converts a function with 6 parameters returning a [R] into a function with 5 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From5[GRA ~func(C) R, F ~func(C, T0, T1, T2, T3, T4) R, T0, T1, T2, T3, T4, C, R any](f F) func(T0, T1, T2, T3, T4) GRA {
|
||||
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2, t3, t4)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From6 converts a function with 7 parameters returning a [R] into a function with 6 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From6[GRA ~func(C) R, F ~func(C, T0, T1, T2, T3, T4, T5) R, T0, T1, T2, T3, T4, T5, C, R any](f F) func(T0, T1, T2, T3, T4, T5) GRA {
|
||||
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2, t3, t4, t5)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From7 converts a function with 8 parameters returning a [R] into a function with 7 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From7[GRA ~func(C) R, F ~func(C, T0, T1, T2, T3, T4, T5, T6) R, T0, T1, T2, T3, T4, T5, T6, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) GRA {
|
||||
return func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2, t3, t4, t5, t6)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From8 converts a function with 9 parameters returning a [R] into a function with 8 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From8[GRA ~func(C) R, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From9 converts a function with 10 parameters returning a [R] into a function with 9 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From9[GRA ~func(C) R, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// From10 converts a function with 11 parameters returning a [R] into a function with 10 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From10[GRA ~func(C) R, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) 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 func(t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8, t9 T9) GRA {
|
||||
return MakeReader[GRA](func(r C) R {
|
||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
|
||||
})
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import (
|
||||
// these functions curry a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[R, A any](f func(R) (A, error)) ReaderEither[R, error, A] {
|
||||
func From0[R, A any](f func(R) (A, error)) func() ReaderEither[R, error, A] {
|
||||
return G.From0[ReaderEither[R, error, A]](f)
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
// these functions From a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[GEA ~func(R) ET.Either[error, A], R, A any](f func(R) (A, error)) GEA {
|
||||
func From0[GEA ~func(R) ET.Either[error, A], R, A any](f func(R) (A, error)) func() GEA {
|
||||
return G.From0[GEA](ET.Eitherize1(f))
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
// these functions From a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[R, A any](f func(R) IO.IO[A]) ReaderIO[R, A] {
|
||||
func From0[R, A any](f func(R) IO.IO[A]) func() ReaderIO[R, A] {
|
||||
return G.From0[ReaderIO[R, A]](f)
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
// these functions From a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[GEA ~func(R) GIOA, GIOA ~func() A, R, A any](f func(R) GIOA) GEA {
|
||||
func From0[GEA ~func(R) GIOA, GIOA ~func() A, R, A any](f func(R) GIOA) func() GEA {
|
||||
return G.From0[GEA](f)
|
||||
}
|
||||
|
||||
|
3
readerioeither/doc.go
Normal file
3
readerioeither/doc.go
Normal file
@ -0,0 +1,3 @@
|
||||
package readerioeither
|
||||
|
||||
//go:generate go run .. readerioeither --count 10 --filename gen.go
|
@ -1,24 +0,0 @@
|
||||
package readerioeither
|
||||
|
||||
import (
|
||||
G "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// these functions From a golang function with the context as the firsr parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[R, A any](f func(R) func() (A, error)) ReaderIOEither[R, error, A] {
|
||||
return G.From0[ReaderIOEither[R, error, A]](f)
|
||||
}
|
||||
|
||||
func From1[R, T1, A any](f func(R, T1) func() (A, error)) func(T1) ReaderIOEither[R, error, A] {
|
||||
return G.From1[ReaderIOEither[R, error, A]](f)
|
||||
}
|
||||
|
||||
func From2[R, T1, T2, A any](f func(R, T1, T2) func() (A, error)) func(T1, T2) ReaderIOEither[R, error, A] {
|
||||
return G.From2[ReaderIOEither[R, error, A]](f)
|
||||
}
|
||||
|
||||
func From3[R, T1, T2, T3, A any](f func(R, T1, T2, T3) func() (A, error)) func(T1, T2, T3) ReaderIOEither[R, error, A] {
|
||||
return G.From3[ReaderIOEither[R, error, A]](f)
|
||||
}
|
141
readerioeither/gen.go
Normal file
141
readerioeither/gen.go
Normal file
@ -0,0 +1,141 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-18 15:21:45.9564072 +0200 CEST m=+0.081399101
|
||||
package readerioeither
|
||||
|
||||
|
||||
import (
|
||||
G "github.com/ibm/fp-go/readerioeither/generic"
|
||||
)
|
||||
|
||||
// From0 converts a function with 1 parameters returning a tuple into a function with 0 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From0[F ~func(C) func() (R, error), C, R any](f F) func() ReaderIOEither[C, error, R] {
|
||||
return G.From0[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize0 converts a function with 1 parameters returning a tuple into a function with 0 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize0[F ~func(C) (R, error), C, R any](f F) func() ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize0[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From1 converts a function with 2 parameters returning a tuple into a function with 1 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From1[F ~func(C, T0) func() (R, error), T0, C, R any](f F) func(T0) ReaderIOEither[C, error, R] {
|
||||
return G.From1[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize1 converts a function with 2 parameters returning a tuple into a function with 1 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize1[F ~func(C, T0) (R, error), T0, C, R any](f F) func(T0) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize1[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From2 converts a function with 3 parameters returning a tuple into a function with 2 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From2[F ~func(C, T0, T1) func() (R, error), T0, T1, C, R any](f F) func(T0, T1) ReaderIOEither[C, error, R] {
|
||||
return G.From2[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize2 converts a function with 3 parameters returning a tuple into a function with 2 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize2[F ~func(C, T0, T1) (R, error), T0, T1, C, R any](f F) func(T0, T1) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize2[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From3 converts a function with 4 parameters returning a tuple into a function with 3 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From3[F ~func(C, T0, T1, T2) func() (R, error), T0, T1, T2, C, R any](f F) func(T0, T1, T2) ReaderIOEither[C, error, R] {
|
||||
return G.From3[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize3 converts a function with 4 parameters returning a tuple into a function with 3 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize3[F ~func(C, T0, T1, T2) (R, error), T0, T1, T2, C, R any](f F) func(T0, T1, T2) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize3[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From4 converts a function with 5 parameters returning a tuple into a function with 4 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From4[F ~func(C, T0, T1, T2, T3) func() (R, error), T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) ReaderIOEither[C, error, R] {
|
||||
return G.From4[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize4 converts a function with 5 parameters returning a tuple into a function with 4 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize4[F ~func(C, T0, T1, T2, T3) (R, error), T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize4[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From5 converts a function with 6 parameters returning a tuple into a function with 5 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From5[F ~func(C, T0, T1, T2, T3, T4) func() (R, error), T0, T1, T2, T3, T4, C, R any](f F) func(T0, T1, T2, T3, T4) ReaderIOEither[C, error, R] {
|
||||
return G.From5[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize5 converts a function with 6 parameters returning a tuple into a function with 5 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize5[F ~func(C, T0, T1, T2, T3, T4) (R, error), T0, T1, T2, T3, T4, C, R any](f F) func(T0, T1, T2, T3, T4) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize5[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From6 converts a function with 7 parameters returning a tuple into a function with 6 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From6[F ~func(C, T0, T1, T2, T3, T4, T5) func() (R, error), T0, T1, T2, T3, T4, T5, C, R any](f F) func(T0, T1, T2, T3, T4, T5) ReaderIOEither[C, error, R] {
|
||||
return G.From6[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize6 converts a function with 7 parameters returning a tuple into a function with 6 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize6[F ~func(C, T0, T1, T2, T3, T4, T5) (R, error), T0, T1, T2, T3, T4, T5, C, R any](f F) func(T0, T1, T2, T3, T4, T5) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize6[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From7 converts a function with 8 parameters returning a tuple into a function with 7 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From7[F ~func(C, T0, T1, T2, T3, T4, T5, T6) func() (R, error), T0, T1, T2, T3, T4, T5, T6, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) ReaderIOEither[C, error, R] {
|
||||
return G.From7[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize7 converts a function with 8 parameters returning a tuple into a function with 7 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize7[F ~func(C, T0, T1, T2, T3, T4, T5, T6) (R, error), T0, T1, T2, T3, T4, T5, T6, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize7[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From8 converts a function with 9 parameters returning a tuple into a function with 8 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From8[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) func() (R, error), T0, T1, T2, T3, T4, T5, T6, T7, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) ReaderIOEither[C, error, R] {
|
||||
return G.From8[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize8 converts a function with 9 parameters returning a tuple into a function with 8 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize8[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize8[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From9 converts a function with 10 parameters returning a tuple into a function with 9 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From9[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) func() (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) ReaderIOEither[C, error, R] {
|
||||
return G.From9[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize9 converts a function with 10 parameters returning a tuple into a function with 9 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize9[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) (R, error), T0, T1, T2, T3, T4, T5, T6, T7, T8, C, R any](f F) func(T0, T1, T2, T3, T4, T5, T6, T7, T8) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize9[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// From10 converts a function with 11 parameters returning a tuple into a function with 10 parameters returning a [ReaderIOEither[R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func From10[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) func() (R, error), 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) ReaderIOEither[C, error, R] {
|
||||
return G.From10[ReaderIOEither[C, error, R]](f)
|
||||
}
|
||||
|
||||
// Eitherize10 converts a function with 11 parameters returning a tuple into a function with 10 parameters returning a [ReaderIOEither[C, error, R]]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize10[F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (R, error), 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) ReaderIOEither[C, error, R] {
|
||||
return G.Eitherize10[ReaderIOEither[C, error, R]](f)
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
ET "github.com/ibm/fp-go/either"
|
||||
)
|
||||
|
||||
// these functions From a golang function with the context as the first parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func Eitherize0[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, A any](f func(R) (A, error)) GEA {
|
||||
return From0[GEA](func(r R) func() (A, error) {
|
||||
return func() (A, error) {
|
||||
return f(r)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Eitherize1[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, A any](f func(R, T1) (A, error)) func(T1) GEA {
|
||||
return From1[GEA](func(r R, t1 T1) func() (A, error) {
|
||||
return func() (A, error) {
|
||||
return f(r, t1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Eitherize2[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, T2, A any](f func(R, T1, T2) (A, error)) func(T1, T2) GEA {
|
||||
return From2[GEA](func(r R, t1 T1, t2 T2) func() (A, error) {
|
||||
return func() (A, error) {
|
||||
return f(r, t1, t2)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Eitherize3[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, T2, T3, A any](f func(R, T1, T2, T3) (A, error)) func(T1, T2, T3) GEA {
|
||||
return From3[GEA](func(r R, t1 T1, t2 T2, t3 T3) func() (A, error) {
|
||||
return func() (A, error) {
|
||||
return f(r, t1, t2, t3)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Eitherize4[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, T2, T3, T4, A any](f func(R, T1, T2, T3, T4) (A, error)) func(T1, T2, T3, T4) GEA {
|
||||
return From4[GEA](func(r R, t1 T1, t2 T2, t3 T3, t4 T4) func() (A, error) {
|
||||
return func() (A, error) {
|
||||
return f(r, t1, t2, t3, t4)
|
||||
}
|
||||
})
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
ET "github.com/ibm/fp-go/either"
|
||||
G "github.com/ibm/fp-go/reader/generic"
|
||||
)
|
||||
|
||||
// these functions From a golang function with the context as the first parameter into a either reader with the context as the last parameter
|
||||
// this goes back to the advice in https://pkg.go.dev/context to put the context as a first parameter as a convention
|
||||
|
||||
func From0[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, A any](f func(R) func() (A, error)) GEA {
|
||||
return G.From0[GEA](func(r R) GIOA {
|
||||
return ET.Eitherize0(f(r))
|
||||
})
|
||||
}
|
||||
|
||||
func From1[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, A any](f func(R, T1) func() (A, error)) func(T1) GEA {
|
||||
return G.From1[GEA](func(r R, t1 T1) GIOA {
|
||||
return ET.Eitherize0(f(r, t1))
|
||||
})
|
||||
}
|
||||
|
||||
func From2[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, T2, A any](f func(R, T1, T2) func() (A, error)) func(T1, T2) GEA {
|
||||
return G.From2[GEA](func(r R, t1 T1, t2 T2) GIOA {
|
||||
return ET.Eitherize0(f(r, t1, t2))
|
||||
})
|
||||
}
|
||||
|
||||
func From3[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, T2, T3, A any](f func(R, T1, T2, T3) func() (A, error)) func(T1, T2, T3) GEA {
|
||||
return G.From3[GEA](func(r R, t1 T1, t2 T2, t3 T3) GIOA {
|
||||
return ET.Eitherize0(f(r, t1, t2, t3))
|
||||
})
|
||||
}
|
||||
|
||||
func From4[GEA ~func(R) GIOA, GIOA ~func() ET.Either[error, A], R, T1, T2, T3, T4, A any](f func(R, T1, T2, T3, T4) func() (A, error)) func(T1, T2, T3, T4) GEA {
|
||||
return G.From4[GEA](func(r R, t1 T1, t2 T2, t3 T3, t4 T4) GIOA {
|
||||
return ET.Eitherize0(f(r, t1, t2, t3, t4))
|
||||
})
|
||||
}
|
197
readerioeither/generic/gen.go
Normal file
197
readerioeither/generic/gen.go
Normal file
@ -0,0 +1,197 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-18 15:21:45.957526 +0200 CEST m=+0.082517901
|
||||
package generic
|
||||
|
||||
|
||||
import (
|
||||
E "github.com/ibm/fp-go/either"
|
||||
RD "github.com/ibm/fp-go/reader/generic"
|
||||
)
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize0 converts a function with 0 parameters returning a tuple into a function with 0 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize0[GRA ~func(C) GIOA, F ~func(C) (R, error), GIOA ~func() E.Either[error, R], C, R any](f F) func() GRA {
|
||||
return From0[GRA](func(r C) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize1 converts a function with 1 parameters returning a tuple into a function with 1 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize1[GRA ~func(C) GIOA, F ~func(C, T0) (R, error), GIOA ~func() E.Either[error, R], T0, C, R any](f F) func(T0) GRA {
|
||||
return From1[GRA](func(r C, t0 T0) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize2 converts a function with 2 parameters returning a tuple into a function with 2 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize2[GRA ~func(C) GIOA, F ~func(C, T0, T1) (R, error), GIOA ~func() E.Either[error, R], T0, T1, C, R any](f F) func(T0, T1) GRA {
|
||||
return From2[GRA](func(r C, t0 T0, t1 T1) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1, t2))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize3 converts a function with 3 parameters returning a tuple into a function with 3 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize3[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, C, R any](f F) func(T0, T1, T2) GRA {
|
||||
return From3[GRA](func(r C, t0 T0, t1 T1, t2 T2) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1, t2)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1, t2, t3))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize4 converts a function with 4 parameters returning a tuple into a function with 4 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize4[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3) (R, error), GIOA ~func() E.Either[error, R], T0, T1, T2, T3, C, R any](f F) func(T0, T1, T2, T3) GRA {
|
||||
return From4[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1, t2, t3)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1, t2, t3, t4))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize5 converts a function with 5 parameters returning a tuple into a function with 5 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize5[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4) (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 From5[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1, t2, t3, t4)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize6 converts a function with 6 parameters returning a tuple into a function with 6 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize6[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5) (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 From6[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1, t2, t3, t4, t5)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize7 converts a function with 7 parameters returning a tuple into a function with 7 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize7[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6) (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 From7[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1, t2, t3, t4, t5, t6)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize8 converts a function with 8 parameters returning a tuple into a function with 8 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize8[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7) (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 From8[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, 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]
|
||||
// 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 {
|
||||
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 E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize9 converts a function with 9 parameters returning a tuple into a function with 9 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize9[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8) (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 From9[GRA](func(r C, t0 T0, t1 T1, t2 T2, t3 T3, t4 T4, t5 T5, t6 T6, t7 T7, t8 T8) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8)
|
||||
}})
|
||||
}
|
||||
|
||||
// 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].
|
||||
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 E.Eitherize0(f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9))
|
||||
})
|
||||
}
|
||||
|
||||
// Eitherize10 converts a function with 10 parameters returning a tuple into a function with 10 parameters returning a [GRA]
|
||||
// The first parameter is considered to be the context [C].
|
||||
func Eitherize10[GRA ~func(C) GIOA, F ~func(C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) (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 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) func() (R, error) {
|
||||
return func() (R, error) {
|
||||
return f(r, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)
|
||||
}})
|
||||
}
|
@ -1,3 +1,18 @@
|
||||
// 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 record
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,17 @@
|
||||
// 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 record
|
||||
|
||||
import (
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 465 KiB After Width: | Height: | Size: 242 KiB |
@ -1,6 +1,6 @@
|
||||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2023-07-17 17:36:57.1507964 +0200 CEST m=+0.013497601
|
||||
// 2023-07-18 15:21:49.4411816 +0200 CEST m=+0.105633301
|
||||
package tuple
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user