Skip to content

feat: add scan combinator for iterators#1590

Open
cmlsharp wants to merge 140 commits intoleanprover-community:mainfrom
cmlsharp:scan-iter'
Open

feat: add scan combinator for iterators#1590
cmlsharp wants to merge 140 commits intoleanprover-community:mainfrom
cmlsharp:scan-iter'

Conversation

@cmlsharp
Copy link
Copy Markdown
Contributor

This PR depends on:

This PR was originally #1585, but I split the PR it was based on into multiple PRs and wanted to avoid merge conflicts.

This PR builds off of my earlier PRs and adds a Scan combinator to Iterators as well (the dependence on the earlier PRs is just for the lemmas that prove correspondence between the iterator combinators and their list/array equivalents).

The primary contribution of this PR is IterM.scanM which, given an effectful iterator, an inital value, and an effectful accumulation function, returns an iterator over the partial results of folding that function over the values of the inner iterator. The remaining Iter.Scan/Iter.ScanM/IterM.scan are just implemented in terms of this in the obvious way.

This PR includes instances for both Productive and Finite (if the underlying iterator is Productive, resp. Finite) and includes lemmas showing that (at least for pure iterators / iterators in the identity monad) Iter.scan* is equivalent to accumulating the values into a list (resp. Array) and then calling List.scanl/List.scanlM (resp. Array.scanl/Array.scanlM). I would be happy to continue plugging away at more theorems, but this seems like a minimally useful set.

@github-actions github-actions bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Dec 31, 2025
@cmlsharp
Copy link
Copy Markdown
Contributor Author

At present IterM.scanM does not make use of the recently introduced MonadAttach at present. This seems to only be available on nightly at the moment.

@cmlsharp
Copy link
Copy Markdown
Contributor Author

cmlsharp commented Jan 5, 2026

WIP

@github-actions github-actions bot added WIP work in progress and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Jan 5, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Feb 24, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts bot removed the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Feb 26, 2026
mathlib-nightly-testing bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 27, 2026
@fgdorais fgdorais added depends on core changes This PR need only be reviewed after changes land in Lean core. and removed awaiting-review This PR is ready for review; the author thinks it is ready to be merged. labels Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib depends on core changes This PR need only be reviewed after changes land in Lean core.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants