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 try_[zip_[zip_]]map methods to Matrix #1142

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Patiga
Copy link
Contributor

@Patiga Patiga commented Aug 18, 2022

I'm building a library where I want to catch overflows of integer calculations.
I didn't see a method with which I could flatten Options in a matrix, which would've been a workaround (the closest would maybe be something with fold).
Such a function would also not short-circuit and result in at least one more copy, although it could also be considered.

The try_[zip_[zip_]]map are just like their non-try counterparts, except that they accept a function that returns an Option.
If the function returns None for any of the elements, None is returned.
Otherwise, a matrix with all the Some values is returned (not wrapped in the Option)

Short example

vector
    .try_map(|n| n.checked_mul(100))?
    .try_zip_map(parallax, |(n, p)| n.checked_div(p))?

I am also using another non-std integer type, from the fixed crate.
Afaik, try_map also helps here because of fallible conversions.

Useful for functions that can fail
- integer `_checked` methods
- fallible conversions
@Patiga Patiga changed the title Add try_[zip_[zip_]map methods to Matrix Add try_[zip_[zip_]]map methods to Matrix Aug 18, 2022
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.

None yet

1 participant