Skip to content

Commit

Permalink
Merge pull request #40 from IBM/cleue-add-missing-lenses
Browse files Browse the repository at this point in the history
fix: change Cache to Memoize and fix order of parameters to ToType
  • Loading branch information
CarstenLeue authored Sep 10, 2023
2 parents 03debd3 + a83c2ae commit 3812076
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion either/either.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions function/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion function/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestCache(t *testing.T) {
return n
}

cached := Cache(withSideEffect)
cached := Memoize(withSideEffect)

assert.Equal(t, 0, count)

Expand Down
10 changes: 5 additions & 5 deletions function/generic/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]())
}

Expand Down

0 comments on commit 3812076

Please sign in to comment.