|
| 1 | +/// Type bindings for Python functools module: https://docs.python.org/3/library/functools.html |
| 2 | +module Fable.Python.Functools |
| 3 | + |
| 4 | +open Fable.Core |
| 5 | + |
| 6 | +// fsharplint:disable MemberNames |
| 7 | + |
| 8 | +[<Erase>] |
| 9 | +type IExports = |
| 10 | + // ======================================================================== |
| 11 | + // Higher-order functions |
| 12 | + // ======================================================================== |
| 13 | + |
| 14 | + /// Apply a function of two arguments cumulatively to the items of an iterable, |
| 15 | + /// reducing it to a single value (fold-left without a seed). |
| 16 | + /// See https://docs.python.org/3/library/functools.html#functools.reduce |
| 17 | + abstract reduce: func: System.Func<'T, 'T, 'T> * iterable: 'T seq -> 'T |
| 18 | + |
| 19 | + /// Apply a function of two arguments cumulatively to the items of an iterable, |
| 20 | + /// starting with the initializer as the seed value (fold-left with a seed). |
| 21 | + /// See https://docs.python.org/3/library/functools.html#functools.reduce |
| 22 | + [<Emit("$0.reduce($1, $2, $3)")>] |
| 23 | + abstract reduce: func: System.Func<'State, 'T, 'State> * iterable: 'T seq * initializer: 'State -> 'State |
| 24 | + |
| 25 | + // ======================================================================== |
| 26 | + // Caching decorators |
| 27 | + // ======================================================================== |
| 28 | + |
| 29 | + /// Wrap func with an LRU (least-recently-used) cache of at most maxsize entries. |
| 30 | + /// Returns a memoised callable with the same signature as func. |
| 31 | + /// Requires Python 3.8+. |
| 32 | + /// See https://docs.python.org/3/library/functools.html#functools.lru_cache |
| 33 | + [<Emit("$0.lru_cache(maxsize=int($1))($2)")>] |
| 34 | + abstract lruCache: maxsize: int * func: ('T -> 'R) -> ('T -> 'R) |
| 35 | + |
| 36 | + /// Wrap func with an unbounded cache (equivalent to lru_cache(maxsize=None)). |
| 37 | + /// Requires Python 3.9+. |
| 38 | + /// See https://docs.python.org/3/library/functools.html#functools.cache |
| 39 | + [<Emit("$0.cache($1)")>] |
| 40 | + abstract cache: func: ('T -> 'R) -> ('T -> 'R) |
| 41 | + |
| 42 | +/// Higher-order functions and operations on callable objects |
| 43 | +[<ImportAll("functools")>] |
| 44 | +let functools: IExports = nativeOnly |
0 commit comments