mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-23 00:27:49 +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])
|
||||
}
|
||||
|
||||
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 F.Pipe2(
|
||||
value,
|
||||
|
@ -19,12 +19,12 @@ import (
|
||||
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
|
||||
func Cache[K comparable, T any](f func(K) T) func(K) T {
|
||||
return G.Cache(f)
|
||||
// Memoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||
func Memoize[K comparable, T any](f func(K) T) func(K) T {
|
||||
return G.Memoize(f)
|
||||
}
|
||||
|
||||
// ContramapCache 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 {
|
||||
return G.ContramapCache[func(A) T](kf)
|
||||
// ContramapMemoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||
func ContramapMemoize[A any, K comparable, T any](kf func(A) K) func(func(A) T) func(A) T {
|
||||
return G.ContramapMemoize[func(A) T](kf)
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func TestCache(t *testing.T) {
|
||||
return n
|
||||
}
|
||||
|
||||
cached := Cache(withSideEffect)
|
||||
cached := Memoize(withSideEffect)
|
||||
|
||||
assert.Equal(t, 0, count)
|
||||
|
||||
|
@ -21,13 +21,13 @@ import (
|
||||
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
|
||||
func Cache[F ~func(K) T, K comparable, T any](f F) F {
|
||||
return ContramapCache[F](func(k K) K { return k })(f)
|
||||
// Memoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||
func Memoize[F ~func(K) T, K comparable, T any](f F) 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
|
||||
func ContramapCache[F ~func(A) T, KF func(A) K, A any, K comparable, T any](kf KF) func(F) F {
|
||||
// ContramapMemoize converts a unary function into a unary function that caches the value depending on the parameter
|
||||
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]())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user