shvaikalesh / mem

Tiny, modern memoization library for unary functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mem

Tiny, modern memoization library for unary functions

Up and running

Get the package right from GitHub repository:

npm install --save shvaikalesh/mem

Use default export:

import mem from "mem"

Caching

  • Objects: identity-based, weakly-referenced
  • Primitives: SameValueZero algorithm

Example

Utilizing template caching (see [[TemplateMap]]) to speed up tagged literals:

const dropSpaces = mem(raw => {
  return raw.map(str => str.replace(/\s+/g, ""))
})

export default ({raw}, ...vals) => {
  return String.raw({raw: dropSpaces(raw)}, ...vals)
}

About

Tiny, modern memoization library for unary functions


Languages

Language:JavaScript 100.0%