/** * Python functools module for TypeScript * * Provides higher-order functions and operations on callable objects, * including partial application, function caching (lru_cache), and reduce. * * @see {@link https://docs.python.org/3/library/functools.html | Python functools documentation} * @module */ /** * Create a partial function application * partial(func, arg1, arg2) returns a function that calls func with arg1, arg2 prepended * * Example: * const add = (a: number, b: number) => a + b * const add5 = partial(add, 5) * add5(3) // returns 8 */ declare function partial unknown>(func: T, ...partialArgs: unknown[]): (...args: unknown[]) => ReturnType; /** * Apply a function of two arguments cumulatively to the items of an iterable * reduce((x, y) => x + y, [1, 2, 3, 4, 5]) returns 15 * reduce((x, y) => x + y, [1, 2, 3, 4, 5], 10) returns 25 */ declare function reduce(func: (acc: U, val: T) => U, iterable: Iterable, initializer?: U): U; /** * Simple LRU cache decorator (returns a memoized version of the function) * Note: This is a simplified implementation that caches based on JSON-stringified arguments * * Example: * const fib = lruCache((n: number): number => n <= 1 ? n : fib(n - 1) + fib(n - 2)) */ declare function lruCache unknown>(func: T, maxsize?: number): T & { cacheInfo: () => { hits: number; misses: number; maxsize: number; currsize: number; }; cacheClear: () => void; }; /** * Cache decorator that caches all calls (no size limit) * Equivalent to lru_cache(maxsize=None) */ declare function cache unknown>(func: T): T; /** * Return a new partial object which behaves like func called with keyword arguments * In TypeScript, we simulate this with an options object as the last argument */ declare function partialMethod unknown>(func: T, ...partialArgs: unknown[]): (...args: unknown[]) => ReturnType; /** * Transform a function into a single-dispatch generic function * This is a simplified version - full singleDispatch would require runtime type checking */ declare function singleDispatch unknown>(func: T): T & { register: (type: string, impl: T) => void; }; /** * Decorator to update a wrapper function to look like the wrapped function * In TypeScript, this just returns the wrapper as-is (metadata is handled differently) */ declare function wraps unknown>(wrapped: T): (wrapper: (...args: unknown[]) => unknown) => T; /** * Return a callable object that fetches attr from its operand * attrGetter('name') returns a function that gets the 'name' attribute */ declare function attrGetter(...attrs: string[]): (obj: unknown) => T | T[]; /** * Return a callable object that fetches item from its operand * itemGetter(1) returns a function that gets index 1 * itemGetter('key') returns a function that gets the 'key' property */ declare function itemGetter(...items: (string | number)[]): (obj: unknown) => T | T[]; /** * Return a callable object that calls the method name on its operand * methodCaller('split', ' ') returns a function that calls .split(' ') */ declare function methodCaller(name: string, ...args: unknown[]): (obj: unknown) => unknown; /** * Return the same object passed in (identity function) */ declare function identity(x: T): T; /** * Compare two objects for ordering (returns -1, 0, or 1) * Used for sorting with a key function */ declare function cmpToKey(mycmp: (a: T, b: T) => number): (x: T) => { value: T; __lt__: (other: { value: T; }) => boolean; }; /** * Return total ordering for a class that has __lt__, __le__, __gt__, or __ge__ * This is typically used as a class decorator in Python * In TypeScript, we provide helper comparisons */ declare function totalOrdering boolean; __le__?: (other: T) => boolean; __gt__?: (other: T) => boolean; __ge__?: (other: T) => boolean; __eq__?: (other: T) => boolean; }>(obj: T): T & { __lt__: (other: T) => boolean; __le__: (other: T) => boolean; __gt__: (other: T) => boolean; __ge__: (other: T) => boolean; }; /** * Pipe a value through a series of functions. * @inspired Remeda, Ramda * * Example: * pipe(5, x => x * 2, x => x + 1) // returns 11 */ declare function pipe(value: T): T; declare function pipe(value: T, fn1: (x: T) => A): A; declare function pipe(value: T, fn1: (x: T) => A, fn2: (x: A) => B): B; declare function pipe(value: T, fn1: (x: T) => A, fn2: (x: A) => B, fn3: (x: B) => C): C; declare function pipe(value: T, fn1: (x: T) => A, fn2: (x: A) => B, fn3: (x: B) => C, fn4: (x: C) => D): D; declare function pipe(value: T, fn1: (x: T) => A, fn2: (x: A) => B, fn3: (x: B) => C, fn4: (x: C) => D, fn5: (x: D) => E): E; declare const functoolsModule_attrGetter: typeof attrGetter; declare const functoolsModule_cache: typeof cache; declare const functoolsModule_cmpToKey: typeof cmpToKey; declare const functoolsModule_identity: typeof identity; declare const functoolsModule_itemGetter: typeof itemGetter; declare const functoolsModule_lruCache: typeof lruCache; declare const functoolsModule_methodCaller: typeof methodCaller; declare const functoolsModule_partial: typeof partial; declare const functoolsModule_partialMethod: typeof partialMethod; declare const functoolsModule_pipe: typeof pipe; declare const functoolsModule_reduce: typeof reduce; declare const functoolsModule_singleDispatch: typeof singleDispatch; declare const functoolsModule_totalOrdering: typeof totalOrdering; declare const functoolsModule_wraps: typeof wraps; declare namespace functoolsModule { export { functoolsModule_attrGetter as attrGetter, functoolsModule_cache as cache, functoolsModule_cmpToKey as cmpToKey, functoolsModule_identity as identity, functoolsModule_itemGetter as itemGetter, functoolsModule_lruCache as lruCache, functoolsModule_methodCaller as methodCaller, functoolsModule_partial as partial, functoolsModule_partialMethod as partialMethod, functoolsModule_pipe as pipe, functoolsModule_reduce as reduce, functoolsModule_singleDispatch as singleDispatch, functoolsModule_totalOrdering as totalOrdering, functoolsModule_wraps as wraps }; } export { attrGetter as a, cmpToKey as b, cache as c, itemGetter as d, partialMethod as e, functoolsModule as f, pipe as g, identity as i, lruCache as l, methodCaller as m, partial as p, reduce as r, singleDispatch as s, totalOrdering as t, wraps as w };