/**
 * This function doesn't work with non-primitive arguments
 */ const memoize = < T extends ( ( ... args : any [ ] ) => any ) > ( fn ) : T => { const cache = { } ; return function ( this , ... args ) { const cacheKey = args . length > 1 ? args . join ( '-(:-:)-' ) : args [ 0 ] ; if ( cacheKey in cache ) { return cache [ cacheKey ] ; } const result = fn . apply ( this , args ) ; cache [ cacheKey ] = result ; return result ; } as any ; } ; export default memoize ;