mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-21 00:19:34 +02:00
fix: change Cache to Memoize and fix order of parameters to ToType
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@ -209,7 +209,7 @@ func OrElse[E, A any](onLeft func(e E) Either[E, A]) func(Either[E, A]) Either[E
|
|||||||
return Fold(onLeft, Of[E, A])
|
return Fold(onLeft, Of[E, A])
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToType[E, A any](onError func(any) E) func(any) Either[E, A] {
|
func ToType[A, E any](onError func(any) E) func(any) Either[E, A] {
|
||||||
return func(value any) Either[E, A] {
|
return func(value any) Either[E, A] {
|
||||||
return F.Pipe2(
|
return F.Pipe2(
|
||||||
value,
|
value,
|
||||||
|
@ -19,12 +19,12 @@ import (
|
|||||||
G "github.com/IBM/fp-go/function/generic"
|
G "github.com/IBM/fp-go/function/generic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cache converts a unary function into a unary function that caches the value depending on the parameter
|
// Memoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||||
func Cache[K comparable, T any](f func(K) T) func(K) T {
|
func Memoize[K comparable, T any](f func(K) T) func(K) T {
|
||||||
return G.Cache(f)
|
return G.Memoize(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContramapCache converts a unary function into a unary function that caches the value depending on the parameter
|
// ContramapMemoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||||
func ContramapCache[A any, K comparable, T any](kf func(A) K) func(func(A) T) func(A) T {
|
func ContramapMemoize[A any, K comparable, T any](kf func(A) K) func(func(A) T) func(A) T {
|
||||||
return G.ContramapCache[func(A) T](kf)
|
return G.ContramapMemoize[func(A) T](kf)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func TestCache(t *testing.T) {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
cached := Cache(withSideEffect)
|
cached := Memoize(withSideEffect)
|
||||||
|
|
||||||
assert.Equal(t, 0, count)
|
assert.Equal(t, 0, count)
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ import (
|
|||||||
L "github.com/IBM/fp-go/internal/lazy"
|
L "github.com/IBM/fp-go/internal/lazy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cache converts a unary function into a unary function that caches the value depending on the parameter
|
// Memoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||||
func Cache[F ~func(K) T, K comparable, T any](f F) F {
|
func Memoize[F ~func(K) T, K comparable, T any](f F) F {
|
||||||
return ContramapCache[F](func(k K) K { return k })(f)
|
return ContramapMemoize[F](func(k K) K { return k })(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContramapCache converts a unary function into a unary function that caches the value depending on the parameter
|
// ContramapMemoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||||
func ContramapCache[F ~func(A) T, KF func(A) K, A any, K comparable, T any](kf KF) func(F) F {
|
func ContramapMemoize[F ~func(A) T, KF func(A) K, A any, K comparable, T any](kf KF) func(F) F {
|
||||||
return CacheCallback[F](kf, getOrCreate[K, T]())
|
return CacheCallback[F](kf, getOrCreate[K, T]())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user