Tiny, modern memoization library for unary functions
Get the package right from GitHub repository:
npm install --save shvaikalesh/mem
Use default
export:
import mem from "mem"
- Objects: identity-based, weakly-referenced
- Primitives:
SameValueZero
algorithm
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)
}