Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Iter.map_while #43

Merged
merged 2 commits into from
Nov 16, 2023
Merged

Add Iter.map_while #43

merged 2 commits into from
Nov 16, 2023

Conversation

OlivierNicole
Copy link
Contributor

I found myself needing this function and didn’t find an easy way to make it in an efficient way by composing simpler functions.

@c-cube
Copy link
Owner

c-cube commented Nov 15, 2023

This seems quite useful indeed. I do have one design question: what if you want to stop before yielding any element (e.g. if the first element is "wrong")?

Would this be more general?

val map_while : ('a -> [`Yield of 'b | `Return of 'b | `Stop]) -> 'a t -> 'b t

where yield means, yield and continue, and return means yield and stop iterating

@OlivierNicole
Copy link
Contributor Author

It does seem more general.

@OlivierNicole
Copy link
Contributor Author

I implemented this version.
Is there a requirement to be compatible with OCaml 4.08? The CI fails for this reason.

@c-cube
Copy link
Owner

c-cube commented Nov 15, 2023

Yes, I'd like to preserve compatibility with 4.08 for now. You can use CCList.equal instead.

tests/unit/t_iter.ml Outdated Show resolved Hide resolved
@c-cube
Copy link
Owner

c-cube commented Nov 16, 2023

I'll merge and fix the tests. Thank you :)

@c-cube c-cube merged commit 63c99cf into c-cube:master Nov 16, 2023
0 of 4 checks passed
@OlivierNicole OlivierNicole deleted the map_while branch November 16, 2023 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants