Skip to content

feat(stdlib): add itertools module bindings#256

Merged
dbrattli merged 2 commits intomainfrom
repo-assist/bindings-itertools-module-ebbe049be8b5ba52
Apr 17, 2026
Merged

feat(stdlib): add itertools module bindings#256
dbrattli merged 2 commits intomainfrom
repo-assist/bindings-itertools-module-ebbe049be8b5ba52

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes N/A — proactive bindings expansion (Task 8: Bindings Coverage Improvements).

What

Adds F# bindings for Python's [itertools]((docs.python.org/redacted) module — a popular stdlib module with no existing coverage.

Infinite iterators: count, cycle, repeat

Finite iterators: accumulate, chain (2/3/4-arg + chainFromIterable), compress, dropwhile, filterfalse, groupby, islice (stop / start+stop / start+stop+step), pairwise (Python 3.10+), takewhile, zip_longest

Combinatoric iterators: permutations, combinations, combinationsWithReplacement, product

Why

itertools is one of the most commonly used Python stdlib modules, especially for functional-style code — exactly the kind of code F# developers write. It was entirely missing from Fable.Python.

Design notes

  • All functions follow the same [<ImportAll("itertools")>] / [<Erase>] pattern used throughout src/stdlib/.
  • Functions that Python calls with two positional arguments (accumulate with a binary function) use [<Emit("... lambda a, b: $2(a)(b) ...")] to correctly bridge Fable's curried F# functions to Python's 2-arg callables.
  • chain.from_iterable is exposed as chainFromIterable via [<Emit>] since dotted method names can't be expressed in F# identifiers.
  • pairwise requires Python 3.10+; this is documented in the XML doc comment.
  • groupby returns seq<'K * seq<'T>>; the doc comment warns that group iterators share the underlying iterator (standard Python groupby caveat).
  • All return types are seq<'T> (lazy), consistent with Python's iterator semantics. Callers can pipe to Seq.toList etc.

Tests

20 tests added in test/TestItertools.fs covering all major functions.

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 · ● 3.1M ·

Add comprehensive F# bindings for Python's itertools module including:
- Infinite iterators: count, cycle, repeat
- Finite iterators: accumulate, chain, chainFromIterable, compress,
  dropwhile, filterfalse, groupby, islice, pairwise, takewhile, zip_longest
- Combinatoric iterators: permutations, combinations,
  combinationsWithReplacement, product

Also adds 20 tests in TestItertools.fs covering all major functions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dbrattli dbrattli changed the title [Repo Assist] feat(stdlib): add itertools module bindings feat(stdlib): add itertools module bindings Apr 17, 2026
- accumulate with func: replace curried lambda bridge with System.Func<_,_,_>.
  Fable uncurries F# binary functions to 2-arg Python callables, so the
  previous lambda a,b: f(a)(b) wrapper failed at runtime. System.Func
  compiles directly to a 2-arg Python callable and also unblocks overload
  resolution (curried arg methods can't be overloaded).
- permutations / combinations / combinations_with_replacement / product
  (repeat overload): change return type from seq<'T[]> / seq<ResizeArray<'T>>
  to seq<'T seq>. Python itertools yields tuples, which don't compare equal
  to F# arrays; seq<'T seq> matches the tuple shape and lets callers pick
  their own materialization.
- Revert CHANGELOG.md edit per AGENTS.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dbrattli dbrattli marked this pull request as ready for review April 17, 2026 04:57
@dbrattli dbrattli merged commit 6a4d816 into main Apr 17, 2026
2 checks passed
@dbrattli dbrattli deleted the repo-assist/bindings-itertools-module-ebbe049be8b5ba52 branch April 17, 2026 05:00
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