1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-10 22:31:32 +02:00

fix: automate eitherize methods

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-18 15:24:00 +02:00
parent 2efe4f64c5
commit eb4975e86d
60 changed files with 2106 additions and 430 deletions

3
reader/doc.go Normal file
View File

@@ -0,0 +1,3 @@
package reader
//go:generate go run .. reader --count 10 --filename gen.go

View File

@@ -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
View 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)
}

View File

@@ -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
View 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)
})
}
}