* Creates a function that memoizes the result of `func`. If `resolver` is * provided, it determines the cache key for storing the result based on the * arguments provided to the memoized function. By default, the first argument * provided to the memoized function is used as the map cache key. The
(func, resolver)
| 776 | * _.memoize.Cache = WeakMap; |
| 777 | */ |
| 778 | function memoize(func, resolver) { |
| 779 | if ( |
| 780 | typeof func != 'function' || |
| 781 | (resolver && typeof resolver != 'function') |
| 782 | ) { |
| 783 | throw new TypeError(FUNC_ERROR_TEXT); |
| 784 | } |
| 785 | var memoized = function () { |
| 786 | var args = arguments, |
| 787 | key = resolver ? resolver.apply(this, args) : args[0], |
| 788 | cache = memoized.cache; |
| 789 | |
| 790 | if (cache.has(key)) { |
| 791 | return cache.get(key); |
| 792 | } |
| 793 | var result = func.apply(this, args); |
| 794 | memoized.cache = cache.set(key, result); |
| 795 | return result; |
| 796 | }; |
| 797 | memoized.cache = new (memoize.Cache || MapCache)(); |
| 798 | return memoized; |
| 799 | } |
| 800 | |
| 801 | // Assign cache to `_.memoize`. |
| 802 | memoize.Cache = MapCache; |
no outgoing calls
no test coverage detected
searching dependent graphs…