Skip to content

feat(stdlib): add functools module bindings#260

Merged
dbrattli merged 2 commits intomainfrom
repo-assist/bindings-functools-2026-04-19-5cb39bf7ef0c060e
Apr 19, 2026
Merged

feat(stdlib): add functools module bindings#260
dbrattli merged 2 commits intomainfrom
repo-assist/bindings-functools-2026-04-19-5cb39bf7ef0c060e

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 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

F# member Python API Notes
functools.reduce(func, iterable) functools.reduce(fn, it) fold-left, no seed
functools.reduce(func, iterable, initializer) functools.reduce(fn, it, init) fold-left with seed
functools.lruCache(maxsize, func) functools.lru_cache(maxsize=N)(fn) LRU memoisation
functools.cache(func) functools.cache(fn) unbounded memo (Python 3.9+)

Tests

Six tests in test/TestFunctools.fs cover all bindings:

  • reduce — sum without seed, product without seed, integer fold with seed, string fold with seed
  • lruCache — verifies memoisation (only 2 calls for 3 invocations)
  • cache — same memoisation check for unbounded variant

Notes on partial

Python's functools.partial pre-fills positional arguments on multi-arg functions. In Fable, F# lambdas compile to curried Python callables, so partial(f, x) applied to a curried function would return the intermediate closure — not the final result. Binding partial in a type-safe way would require additional design work (e.g. wrapping via System.Func tupled 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

  • Only reduce, lruCache, and cache are bound; partial, wraps, total_ordering, and singledispatch are left for follow-up.
  • lruCache combines the two-step lru_cache(maxsize=N)(fn) call into one F# call using [<Emit>].
  • No breaking changes; pure addition.

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.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Repo Assist · ● 2.3M ·

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>
@dbrattli dbrattli changed the title [Repo Assist] feat(stdlib): add functools module bindings feat(stdlib): add functools module bindings Apr 19, 2026
…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>
@dbrattli dbrattli marked this pull request as ready for review April 19, 2026 13:58
@dbrattli dbrattli merged commit 0db2183 into main Apr 19, 2026
2 checks passed
@dbrattli dbrattli deleted the repo-assist/bindings-functools-2026-04-19-5cb39bf7ef0c060e branch April 19, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant