memoize-pure
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

memoize-pure

low footprint memoize for just pure sync functions with scalar arguments

🔧 Install · 🧩 Example · 📜 API docs · 🔥 Releases · 💪🏼 Contribute · 🖐️ Help


Install

$ npm i memoize-pure

API

Table of Contents

memoize

src/index.ts:16-26

Memoize a function.

const fn = memoize((a, b, c) => some_expensive_calls(a, b, c))
...
const result = fn(1, 2, 3) // => calls the inner function and saves arguments signature "1,2,3"
...
const result = fn(1, 2, 3) // => returns the memoized result immediately since "1,2,3" matches memory

Parameters

  • fn any The function to memoize
  • map A map object to use as memory (optional, default Object.create(null))

Returns any The memoized function

memoizeDebug

src/index.ts:48-89

Debug memoize a function.

const fn = memoizeDebug((a, b, c) => some_expensive_calls(a, b, c))
...
const result = fn(1, 2, 3) // => calls the inner function and saves arguments signature "1,2,3"
...
const result = fn(1, 2, 3) // => returns the memoized result immediately since "1,2,3" matches memory
fn.__memoizeTimesCalled__ // => 1
fn.__memoizeMap__ // => { '1,2,3': 'some result' }

Parameters

  • fn any The function to memoize
  • map (optional, default Object.create(null))
  • threshold (optional, default Infinity)

Returns any The memoized function including two properties:* __memoizeMap__ is the memory map of arguments and results

  • __memoizeTimesCalled__ is the count that the wrapped function has been called

Contribute

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2021 stagas

Readme

Keywords

Package Sidebar

Install

npm i memoize-pure

Weekly Downloads

9

Version

1.0.0

License

MIT

Unpacked Size

21.5 kB

Total Files

9

Last publish

Collaborators

  • stagas