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

fix: get rid of more IO

This commit is contained in:
Dr. Carsten Leue
2025-03-05 00:04:52 +01:00
parent e20679d73c
commit e7e58c9d54
11 changed files with 660 additions and 1378 deletions

View File

@ -39,15 +39,15 @@ func genericIOEither(param string) string {
var extrasIOEither = A.From("E")
func generateIOEitherSequenceT(f, fg *os.File, i int) {
deprecatedGenerateGenericSequenceT(nonGenericIOEither, genericIOEither, extrasIOEither)(f, fg, i)
generateGenericSequenceT(nonGenericIOEither, extrasIOEither)(f, i)
}
func generateIOEitherSequenceTuple(f, fg *os.File, i int) {
deprecatedGenerateGenericSequenceTuple(nonGenericIOEither, genericIOEither, extrasIOEither)(f, fg, i)
generateGenericSequenceTuple(nonGenericIOEither, extrasIOEither)(f, i)
}
func generateIOEitherTraverseTuple(f, fg *os.File, i int) {
deprecatedGenerateGenericTraverseTuple(nonGenericIOEither, genericIOEither, extrasIOEither)(f, fg, i)
generateGenericTraverseTuple(nonGenericIOEither, extrasIOEither)(f, i)
}
func generateIOEitherUneitherize(f, fg *os.File, i int) {
@ -224,7 +224,8 @@ func generateIOEitherHelpers(filename string, count int) error {
fmt.Fprintf(f, `
import (
G "github.com/IBM/fp-go/v2/%s/generic"
T "github.com/IBM/fp-go/v2/tuple"
"github.com/IBM/fp-go/v2/internal/apply"
"github.com/IBM/fp-go/v2/tuple"
)
`, pkg)
@ -238,8 +239,6 @@ import (
fmt.Fprintf(fg, `
import (
ET "github.com/IBM/fp-go/v2/either"
T "github.com/IBM/fp-go/v2/tuple"
A "github.com/IBM/fp-go/v2/internal/apply"
)
`)

View File

@ -306,11 +306,11 @@ func generateGenericSequenceT(
}
fmt.Fprintf(f, ") %s {\n", nonGenericType(tuple))
fmt.Fprintf(f, " return apply.SequenceT%d(\n", i)
fmt.Fprintf(f, " Map[%s, %s],\n", "T1", generateNestedCallbacksPlain(1, i))
fmt.Fprintf(f, " Map[%s],\n", joinAll(", ")(extra, A.From("T1", generateNestedCallbacksPlain(1, i))))
// the apply calls
for j := 2; j <= i; j++ {
fmt.Fprintf(f, " Ap[%s, T%d],\n", generateNestedCallbacksPlain(j, i), j)
fmt.Fprintf(f, " Ap[%s],\n", joinAll(", ")(A.Of(generateNestedCallbacksPlain(j, i)), extra, A.Of(fmt.Sprintf("T%d", j))))
}
// function parameters
for j := 1; j <= i; j++ {
@ -345,11 +345,11 @@ func generateGenericSequenceTuple(
}
fmt.Fprintf(f, "]) %s {\n", nonGenericType(tuple))
fmt.Fprintf(f, " return apply.SequenceTuple%d(\n", i)
fmt.Fprintf(f, " Map[%s, %s],\n", "T1", generateNestedCallbacksPlain(1, i))
fmt.Fprintf(f, " Map[%s],\n", joinAll(", ")(extra, A.From("T1", generateNestedCallbacksPlain(1, i))))
// the apply calls
for j := 2; j <= i; j++ {
fmt.Fprintf(f, " Ap[%s, T%d],\n", generateNestedCallbacksPlain(j, i), j)
fmt.Fprintf(f, " Ap[%s],\n", joinAll(", ")(A.Of(generateNestedCallbacksPlain(j, i)), extra, A.Of(fmt.Sprintf("T%d", j))))
}
// function parameters
@ -383,18 +383,18 @@ func generateGenericTraverseTuple(
return fmt.Sprintf("f%d F%d", j+1, j+1)
})
// return type
paramType := fmt.Sprintf("tuple.Tuple%d[%s]", i, joinAll(", ")(extra, typesA))
returnType := nonGenericType(fmt.Sprintf("tuple.Tuple%d[%s]", i, joinAll(", ")(extra, typesT)))
paramType := fmt.Sprintf("tuple.Tuple%d[%s]", i, joinAll(", ")(typesA))
returnType := nonGenericType(fmt.Sprintf("tuple.Tuple%d[%s]", i, joinAll(", ")(typesT)))
// non generic version
fmt.Fprintf(f, "\n// TraverseTuple%d converts a [%s] into a [%s]\n", i, paramType, returnType)
fmt.Fprintf(f, "func TraverseTuple%d[%s any](%s) func(%s) %s {\n", i, joinAll(", ")(extra, typesF, typesT, typesA), joinAll(", ")(paramF), paramType, returnType)
fmt.Fprintf(f, " return func(t %s) %s {\n", paramType, returnType)
fmt.Fprintf(f, " return apply.TraverseTuple%d(\n", i)
fmt.Fprintf(f, " Map[%s, %s],\n", "T1", generateNestedCallbacksPlain(1, i))
fmt.Fprintf(f, " Map[%s],\n", joinAll(", ")(extra, A.From("T1", generateNestedCallbacksPlain(1, i))))
// the apply calls
for j := 2; j <= i; j++ {
fmt.Fprintf(f, " Ap[%s, T%d],\n", generateNestedCallbacksPlain(j, i), j)
fmt.Fprintf(f, " Ap[%s],\n", joinAll(", ")(A.Of(generateNestedCallbacksPlain(j, i)), extra, A.Of(fmt.Sprintf("T%d", j))))
}
// the function parameters
for j := 1; j <= i; j++ {

View File

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2025-03-04 23:25:32.6587952 +0100 CET m=+0.002669801
// 2025-03-05 00:00:52.4586817 +0100 CET m=+0.002590501
package io

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +0,0 @@
// Copyright (c) 2023 IBM Corp.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package generic
import (
"context"
G "github.com/IBM/fp-go/v2/io/generic"
O "github.com/IBM/fp-go/v2/option"
)
// WithLock executes the provided IO operation in the scope of a lock
func WithLock[GA ~func() O.Option[A], A any](lock func() context.CancelFunc) func(fa GA) GA {
return G.WithLock[GA](lock)
}

View File

@ -18,11 +18,11 @@ package iooption
import (
"context"
IO "github.com/IBM/fp-go/v2/io"
G "github.com/IBM/fp-go/v2/iooption/generic"
"github.com/IBM/fp-go/v2/io"
"github.com/IBM/fp-go/v2/option"
)
// WithLock executes the provided IO operation in the scope of a lock
func WithLock[E, A any](lock IO.IO[context.CancelFunc]) func(fa IOOption[A]) IOOption[A] {
return G.WithLock[IOOption[A]](lock)
func WithLock[E, A any](lock io.IO[context.CancelFunc]) func(fa IOOption[A]) IOOption[A] {
return io.WithLock[option.Option[A]](lock)
}

View File

@ -1,34 +0,0 @@
// Copyright (c) 2023 IBM Corp.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package generic
import (
"context"
F "github.com/IBM/fp-go/v2/function"
G "github.com/IBM/fp-go/v2/io/generic"
)
// WithLock executes the provided IO operation in the scope of a lock
func WithLock[GEA ~func(R) GIOA, GIOA ~func() A, R, A any](lock func() context.CancelFunc) func(fa GEA) GEA {
l := G.WithLock[GIOA](lock)
return func(fa GEA) GEA {
return F.Flow2(
fa,
l,
)
}
}

View File

@ -18,10 +18,17 @@ package readerio
import (
"context"
G "github.com/IBM/fp-go/v2/readerio/generic"
"github.com/IBM/fp-go/v2/function"
"github.com/IBM/fp-go/v2/io"
)
// WithLock executes the provided IO operation in the scope of a lock
func WithLock[R, A any](lock func() context.CancelFunc) func(fa ReaderIO[R, A]) ReaderIO[R, A] {
return G.WithLock[ReaderIO[R, A]](lock)
l := io.WithLock[A](lock)
return func(fa ReaderIO[R, A]) ReaderIO[R, A] {
return function.Flow2(
fa,
l,
)
}
}

View File

@ -1,28 +0,0 @@
// Copyright (c) 2023 IBM Corp.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package generic
import (
"context"
"github.com/IBM/fp-go/v2/either"
G "github.com/IBM/fp-go/v2/readerio/generic"
)
// WithLock executes the provided IO operation in the scope of a lock
func WithLock[GEA ~func(R) GIOA, GIOA ~func() either.Either[E, A], R, E, A any](lock func() context.CancelFunc) func(fa GEA) GEA {
return G.WithLock[GEA](lock)
}

View File

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