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

fix: refactor

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2025-11-11 11:01:49 +01:00
parent 62fcd186a3
commit 600521b220
100 changed files with 1786 additions and 1618 deletions

View File

@@ -82,7 +82,7 @@ func MapWithIndex[A, B any](f func(int, A) B) func([]A) []B {
//
//go:inline
func Map[A, B any](f func(a A) B) func([]A) []B {
return G.Map[[]A, []B, A, B](f)
return G.Map[[]A, []B](f)
}
// MapRef applies a function to a pointer to each element of an array, returning a new array with the results.
@@ -278,7 +278,7 @@ func Of[A any](a A) []A {
//
//go:inline
func MonadChain[A, B any](fa []A, f func(a A) []B) []B {
return G.MonadChain[[]A, []B](fa, f)
return G.MonadChain(fa, f)
}
// Chain applies a function that returns an array to each element and flattens the results.
@@ -291,7 +291,7 @@ func MonadChain[A, B any](fa []A, f func(a A) []B) []B {
//
//go:inline
func Chain[A, B any](f func(A) []B) func([]A) []B {
return G.Chain[[]A, []B](f)
return G.Chain[[]A](f)
}
// MonadAp applies an array of functions to an array of values, producing all combinations.
@@ -314,14 +314,14 @@ func Ap[B, A any](fa []A) func([]func(A) B) []B {
//
//go:inline
func Match[A, B any](onEmpty func() B, onNonEmpty func([]A) B) func([]A) B {
return G.Match[[]A](onEmpty, onNonEmpty)
return G.Match(onEmpty, onNonEmpty)
}
// MatchLeft performs pattern matching on an array, calling onEmpty if empty or onNonEmpty with head and tail if not.
//
//go:inline
func MatchLeft[A, B any](onEmpty func() B, onNonEmpty func(A, []A) B) func([]A) B {
return G.MatchLeft[[]A](onEmpty, onNonEmpty)
return G.MatchLeft(onEmpty, onNonEmpty)
}
// Tail returns all elements except the first, wrapped in an Option.
@@ -390,7 +390,7 @@ func Intersperse[A any](middle A) EM.Endomorphism[[]A] {
// Intercalate inserts a separator between elements and concatenates them using a Monoid.
func Intercalate[A any](m M.Monoid[A]) func(A) func([]A) A {
return func(middle A) func([]A) A {
return Match(m.Empty, F.Flow2(Intersperse(middle), ConcatAll[A](m)))
return Match(m.Empty, F.Flow2(Intersperse(middle), ConcatAll(m)))
}
}
@@ -519,7 +519,7 @@ func Push[A any](a A) EM.Endomorphism[[]A] {
//
//go:inline
func MonadFlap[B, A any](fab []func(A) B, a A) []B {
return G.MonadFlap[func(A) B, []func(A) B, []B, A, B](fab, a)
return G.MonadFlap[func(A) B, []func(A) B, []B](fab, a)
}
// Flap applies a value to an array of functions, producing an array of results.
@@ -527,7 +527,7 @@ func MonadFlap[B, A any](fab []func(A) B, a A) []B {
//
//go:inline
func Flap[B, A any](a A) func([]func(A) B) []B {
return G.Flap[func(A) B, []func(A) B, []B, A, B](a)
return G.Flap[func(A) B, []func(A) B, []B](a)
}
// Prepend adds an element to the beginning of an array, returning a new array.

View File

@@ -97,7 +97,7 @@ func TestAp(t *testing.T) {
utils.Double,
utils.Triple,
},
Ap[int, int]([]int{1, 2, 3}),
Ap[int]([]int{1, 2, 3}),
),
)
}

View File

@@ -34,7 +34,7 @@ import (
func Do[S any](
empty S,
) []S {
return G.Do[[]S, S](empty)
return G.Do[[]S](empty)
}
// Bind attaches the result of a computation to a context S1 to produce a context S2.
@@ -58,7 +58,7 @@ func Bind[S1, S2, T any](
setter func(T) func(S1) S2,
f func(S1) []T,
) func([]S1) []S2 {
return G.Bind[[]S1, []S2, []T, S1, S2, T](setter, f)
return G.Bind[[]S1, []S2](setter, f)
}
// Let attaches the result of a pure computation to a context S1 to produce a context S2.
@@ -80,7 +80,7 @@ func Let[S1, S2, T any](
setter func(T) func(S1) S2,
f func(S1) T,
) func([]S1) []S2 {
return G.Let[[]S1, []S2, S1, S2, T](setter, f)
return G.Let[[]S1, []S2](setter, f)
}
// LetTo attaches a constant value to a context S1 to produce a context S2.
@@ -102,7 +102,7 @@ func LetTo[S1, S2, T any](
setter func(T) func(S1) S2,
b T,
) func([]S1) []S2 {
return G.LetTo[[]S1, []S2, S1, S2, T](setter, b)
return G.LetTo[[]S1, []S2](setter, b)
}
// BindTo initializes a new state S1 from a value T.
@@ -121,7 +121,7 @@ func LetTo[S1, S2, T any](
func BindTo[S1, T any](
setter func(T) S1,
) func([]T) []S1 {
return G.BindTo[[]S1, []T, S1, T](setter)
return G.BindTo[[]S1, []T](setter)
}
// ApS attaches a value to a context S1 to produce a context S2 by considering
@@ -144,5 +144,5 @@ func ApS[S1, S2, T any](
setter func(T) func(S1) S2,
fa []T,
) func([]S1) []S2 {
return G.ApS[[]S1, []S2, []T, S1, S2, T](setter, fa)
return G.ApS[[]S1, []S2](setter, fa)
}

View File

@@ -31,25 +31,25 @@ func Of[GA ~[]A, A any](value A) GA {
func Reduce[GA ~[]A, A, B any](f func(B, A) B, initial B) func(GA) B {
return func(as GA) B {
return MonadReduce[GA](as, f, initial)
return MonadReduce(as, f, initial)
}
}
func ReduceWithIndex[GA ~[]A, A, B any](f func(int, B, A) B, initial B) func(GA) B {
return func(as GA) B {
return MonadReduceWithIndex[GA](as, f, initial)
return MonadReduceWithIndex(as, f, initial)
}
}
func ReduceRight[GA ~[]A, A, B any](f func(A, B) B, initial B) func(GA) B {
return func(as GA) B {
return MonadReduceRight[GA](as, f, initial)
return MonadReduceRight(as, f, initial)
}
}
func ReduceRightWithIndex[GA ~[]A, A, B any](f func(int, A, B) B, initial B) func(GA) B {
return func(as GA) B {
return MonadReduceRightWithIndex[GA](as, f, initial)
return MonadReduceRightWithIndex(as, f, initial)
}
}

View File

@@ -22,19 +22,19 @@ import (
type arrayMonad[A, B any, GA ~[]A, GB ~[]B, GAB ~[]func(A) B] struct{}
func (o *arrayMonad[A, B, GA, GB, GAB]) Of(a A) GA {
return Of[GA, A](a)
return Of[GA](a)
}
func (o *arrayMonad[A, B, GA, GB, GAB]) Map(f func(A) B) func(GA) GB {
return Map[GA, GB, A, B](f)
return Map[GA, GB](f)
}
func (o *arrayMonad[A, B, GA, GB, GAB]) Chain(f func(A) GB) func(GA) GB {
return Chain[GA, GB, A, B](f)
return Chain[GA](f)
}
func (o *arrayMonad[A, B, GA, GB, GAB]) Ap(fa GA) func(GAB) GB {
return Ap[GB, GAB, GA, B, A](fa)
return Ap[GB, GAB](fa)
}
// Monad implements the monadic operations for an array

View File

@@ -97,11 +97,11 @@ func Flatten[A any](mma NonEmptyArray[NonEmptyArray[A]]) NonEmptyArray[A] {
}
func MonadChain[A, B any](fa NonEmptyArray[A], f func(a A) NonEmptyArray[B]) NonEmptyArray[B] {
return G.MonadChain[NonEmptyArray[A], NonEmptyArray[B]](fa, f)
return G.MonadChain(fa, f)
}
func Chain[A, B any](f func(A) NonEmptyArray[B]) func(NonEmptyArray[A]) NonEmptyArray[B] {
return G.Chain[NonEmptyArray[A], NonEmptyArray[B]](f)
return G.Chain[NonEmptyArray[A]](f)
}
func MonadAp[B, A any](fab NonEmptyArray[func(A) B], fa NonEmptyArray[A]) NonEmptyArray[B] {

View File

@@ -94,5 +94,5 @@ func SortByKey[K, T any](ord O.Ord[K], f func(T) K) func(ma []T) []T {
//
//go:inline
func SortBy[T any](ord []O.Ord[T]) func(ma []T) []T {
return G.SortBy[[]T, []O.Ord[T]](ord)
return G.SortBy[[]T](ord)
}

View File

@@ -18,7 +18,7 @@ import (
//
//go:inline
func StrictUniq[A comparable](as []A) []A {
return G.StrictUniq[[]A](as)
return G.StrictUniq(as)
}
// Uniq converts an array of arbitrary items into an array of unique items

View File

@@ -36,7 +36,7 @@ import (
//
//go:inline
func ZipWith[FCT ~func(A, B) C, A, B, C any](fa []A, fb []B, f FCT) []C {
return G.ZipWith[[]A, []B, []C, FCT](fa, fb, f)
return G.ZipWith[[]A, []B, []C](fa, fb, f)
}
// Zip takes two arrays and returns an array of corresponding pairs (tuples).
@@ -79,5 +79,5 @@ func Zip[A, B any](fb []B) func([]A) []T.Tuple2[A, B] {
//
//go:inline
func Unzip[A, B any](cs []T.Tuple2[A, B]) T.Tuple2[[]A, []B] {
return G.Unzip[[]A, []B, []T.Tuple2[A, B]](cs)
return G.Unzip[[]A, []B](cs)
}