Skip to content

Conversation

@cmlsharp
Copy link
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
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
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
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. WIP work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants