Skip to content

forrest-akin/memo-tempo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

memo-tempo

memoizer with a simple api for arg-level expiration

Usage

npm install memo-tempo --save
import memo from 'memo-tempo'

normal memoization

const fib = memo(
    n => n < 2 ? n : fib(n - 1) + fib(n - 2)
)
// values of n memoized indefinitely

set a lifetime for memoized values

const fact = memo(
    n => n < 2 ? 1 : n * fact(n - 1)
, 1000 * 60)
// values of n memoized for 1 minute

each arg can have a different lifetime

const map = memo(
    (iteratee, array) => array.map(iteratee)
, 0, 1000 * 60)
// `iteratee` timeout of 0 indicates neverending memoization
// `array` will remain memoized for 1 minute

bonus: functions are auto-curried!

const mapIds = map(({ id }) => id)
mapIds([
    { id: 1 },
    { id: 2 },
    { id: 3 },
])
//=> [1, 2, 3]

About

memoizer with a simple api for arg-level expiration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published