import type { Fn , Fn2 , Fn3 , Fn4 , FnAny } from "@thi.ng/api" ; import type { MapLike } from "./api.js" ; /**
 * Function memoization for arbitrary argument counts. Returns augmented
 * function, which uses the given `Map` implementation to obtain and
 * store memoized result of given args. Supports generics for up to 4
 * args (otherwise untyped).
 *
 * **Important:** It only makes sense to use `Map` types which support
 * value (rather than object) equality, e.g. those provided by
 *  {@link @thi.ng/associative# | @thi.ng/associative} . Using a native `Map` type here will lead
 * to memory leaks! Alternatively, use  {@link (memoizeJ:1)} .
 *
 *  param fn param cache export function memoize < A , B > ( fn , cache ) ; export function memoize < A , B , C > ( fn , cache ) ; export function memoize < A , B , C , D > ( fn , cache ) ; export function memoize < A , B , C , D , E > ( fn , cache ) ; export function memoize ( fn , cache ) { return ( ... args ) => { let res ; return cache . has ( args ) ? cache . get ( args ) : ( cache . set ( args , ( res = fn . apply ( null , args ) ) ) , res ) ; } ; }