interface MemoizedCall { args : any [ ] ; returnValue : any ; this : any ; } const neverCalled = Symbol ( ) ; type NeverCalled = typeof neverCalled ; /**
 * A simple memoize function, that only stores the last returned value
 * and uses the identity of all passed parameters as a cache key.
 */ function memoizeLast < T extends ( ... args : any [ ] ) => any > ( func ) { let prevCall = neverCalled ; const memoizedFunction = function ( this , ... args ) { if ( prevCall !== neverCalled && prevCall . this === this && prevCall . args . length === args . length && prevCall . args . every ( ( arg , index ) => arg === args [ index ] ) ) { return prevCall . returnValue ; } prevCall = { args , this : this , returnValue : func . apply ( this , args ) , } ; return prevCall . returnValue ; } as T ; return memoizedFunction ; } export { memoizeLast } ;