3.0.2 • Published 1 year ago

@strong-roots-capital/memoize v3.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
1 year ago

memoize

Build Status

Higher-order memoization function

Why?

I couldn't find a simple memoization library that was all of the following

  • stable
  • statically typed
  • control over memory usage
  • used the fastest LRU
  • offered the simplest syntax

Install

npm install @strong-roots-capital/memoize

Use

import { memoize } from '@strong-roots-capital/memoize'

declare function f(parameter: number)

const cacheSize = 100
const memoized = memoize(cacheSize)(f)

// Then use `memoized` in place of `f`
memoized(42)

Note that the underlying LRU is implemented with an es6 map, so cache hits are governed by the rules of Map.prototype.get; for example, objects are compared with strict equality.

As a result, memoize only accepts thunks (functions accepting zero arguments) and unary functions (functions accepting a single argument).

Related

Acknowledgments

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

2 years ago

2.0.0

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

2.0.0-beta.3

3 years ago

1.0.0

3 years ago