import { toString } from '@typed/common' ; import { ArgsOf } from './types' ; param f export const memoize = < F extends ( ... args : any [ ] ) => any > ( f ) : F => { const cache = new Map < any , any > ( ) ; return ( ( ... args ) : ReturnType < F > => { const key = args . reduce ( ( x , y ) => x + toString ( y ) , '' ) ; if ( cache . has ( key ) ) { return cache . get ( key ) ; } let result = f ( ... args ) ; if ( typeof result === 'function' ) { result = memoize ( result ) ; } cache . set ( key , result ) ; return result ; } ) as F ; } ;