-
Notifications
You must be signed in to change notification settings - Fork 90
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 short-circuiting fold_left #2000
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use it in a second function, which actually sparked your initial comment about adding a short-circuiting fold_left
: std.contract.any_of
. The Ok
/Error
cases are reversed though, so you might have to dualize each step and the final result with e.g.
let flip = match {
'Ok x => 'Error x,
'Error x => 'Ok x,
}
As far as I'm concerned, I like the name.
('Ok value) | ||
std.array.try_fold_left | ||
(fun acc Contract => std.contract.apply_as_custom Contract label acc) | ||
value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff is satisfying 😌
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
Fixes #1997, subject to bikeshedding of names.