0.2.0 • Published 8 years ago

funes v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

funes

Remember everything, for better or for worse

Funes is a variadic memoizer: every time a function is called via funes, its output is cached. The next time the same expression is executed, funes returns the cached results instead of executing the function again.

It is a 'floating method', and operates on the function passed as this - which plays nicely with ES7's bind operator (::).

In ES7

import funes from 'funes'

const add = ( a, b ) => {
	console.log( 'Adding!' )

	return a + b
}

add( 1, 2 )
// => 'Adding!'
// => 3

add( 1, 2 )
// => 'Adding!'
// => 3

add::funes( 1, 2 )
// => 'Adding!'
// => 3

add::funes( 1, 2 )
// => 3

In an ES3+ browser

<script src="/lib/funes.es3.js"></script>
<script>
function add( a, b ){
	console.log( 'Adding!' )

	return a + b
}

add( 1, 2 )
// => 'Adding!'
// => 3

add( 1, 2 )
// => 'Adding!'
// => 3

funes.call( add, 1, 2 )
// => 'Adding!'
// => 3

funes.call( add, 1, 2 )
// => 3
</script>
0.2.0

8 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.0

9 years ago