Skip to content
/ memoize Public

A JavaScript function wrapper to memorize / cache result with the same input

License

Notifications You must be signed in to change notification settings

cyan33/memoize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

memoize

🔰 A JavaScript function wrapper to memorize / cache result with the same input

Installation

npm install --save @changyan/memoize

Basic Usage

import { memoize, memoizeAsync } from '@changyan/memoize'

const add = (a, b) => a + b

const memoizedAdd = memoize(add)

memoizedAdd(1, 2) // => 3
memoizedAdd(1, 2) // => return the cached "3"

const getFakeAsyncResult = () => new Promise((resolve, reject) => setTimeout(resolve, 1000))

// and it supports caching async functions
const memoizedGetAsyncResult = memoizeAsync(getFakeAsyncResult)

Contribution

PRs are welcomed!

About

A JavaScript function wrapper to memorize / cache result with the same input

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published