feat(stdlib): add functools module bindings#260
Merged
Conversation
Add Fable.Python.Functools module binding Python's functools stdlib: - reduce: fold-left with and without seed value (2 overloads) - lruCache: LRU-memoised wrapper with configurable maxsize - cache: unbounded memoised wrapper (Python 3.9+, lru_cache(maxsize=None)) Includes 6 tests covering all bindings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rtools - Revert CHANGELOG.md (AGENTS.md forbids PR edits to it). - Use System.Func<_,_,_> for reduce's binary callback to match the accumulate convention in Itertools and ensure Fable uncurries the callable before Python invokes it with two positional arguments. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Summary
Adds
Fable.Python.Functools, binding Python's [functools]((docs.python.org/redacted) standard library module — one of the most frequently used Python stdlib modules in functional-style code.New bindings
functools.reduce(func, iterable)functools.reduce(fn, it)functools.reduce(func, iterable, initializer)functools.reduce(fn, it, init)functools.lruCache(maxsize, func)functools.lru_cache(maxsize=N)(fn)functools.cache(func)functools.cache(fn)Tests
Six tests in
test/TestFunctools.fscover all bindings:reduce— sum without seed, product without seed, integer fold with seed, string fold with seedlruCache— verifies memoisation (only 2 calls for 3 invocations)cache— same memoisation check for unbounded variantNotes on
partialPython's
functools.partialpre-fills positional arguments on multi-arg functions. In Fable, F# lambdas compile to curried Python callables, sopartial(f, x)applied to a curried function would return the intermediate closure — not the final result. Bindingpartialin a type-safe way would require additional design work (e.g. wrapping viaSystem.Functupled signatures). It has been left out intentionally to avoid misleading type signatures; it can be added in a follow-up once the right pattern is established.Trade-offs
reduce,lruCache, andcacheare bound;partial,wraps,total_ordering, andsingledispatchare left for follow-up.lruCachecombines the two-steplru_cache(maxsize=N)(fn)call into one F# call using[<Emit>].Closes none — proactive improvement surfaced from the Future Work backlog.
Note
🔒 Integrity filter blocked 10 items
The following items were blocked because they don't meet the GitHub integrity level.
list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".To allow these resources, lower
min-integrityin your GitHub frontmatter: