feat(stdlib): add itertools module bindings#256
Merged
Conversation
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>
- 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>
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 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,repeatFinite 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_longestCombinatoric iterators:
permutations,combinations,combinationsWithReplacement,productWhy
itertoolsis 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
[<ImportAll("itertools")>]/[<Erase>]pattern used throughoutsrc/stdlib/.accumulatewith 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_iterableis exposed aschainFromIterablevia[<Emit>]since dotted method names can't be expressed in F# identifiers.pairwiserequires Python 3.10+; this is documented in the XML doc comment.groupbyreturnsseq<'K * seq<'T>>; the doc comment warns that group iterators share the underlying iterator (standard Pythongroupbycaveat).seq<'T>(lazy), consistent with Python's iterator semantics. Callers can pipe toSeq.toListetc.Tests
20 tests added in
test/TestItertools.fscovering all major functions.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: