-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement Add on Option types #5328
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
Conversation
This will allow you to use the + operator to add together any two Options, assuming that the contents of each Option likewise implement +. So Some(4) + Some(1) == Some(5), and adding with None leaves the other value unchanged. This might be monoidic? I don't know what that word means!
I don't think this should require |
I think this should work with any binop-with-an-identity (which, wikipedia tells me, is almost a monoid! I don't know whether associativity is a relevant dimension of trying to generalize this. I would, for the sake of not scaring off readers, prefer we not wind up with something called "monoid" in the library) |
@thestinger Yes, I initially tried without the Copy bound and it yelled at me. I'd be happy to forgo it if there's a better solution. |
This will allow you to use the `+` operator to add together any two Options, assuming that the contents of each Option likewise implement `+`. So Some(4) + Some(1) == Some(5), and adding with None leaves the other value unchanged. This might be monoidic? I don't know what that word means!
Can we now go on and make |
What about other operators? |
@sanxiyn I'd need some guidance as to what that would mean. For example: let foo = None;
let bar = Some(4);
let baz = foo - bar; // what is baz? The semantics are easy for addition. Not sure about the rest. |
Also fixes the same for float_arithmetic. changelog: integer_arithmetic,float_arithmetic: fix false negatives with references on integers Fixes rust-lang#5328
…flip1995 integer_arithmetic: detect integer arithmetic on references. changelog: integer_arithmetic fix false negatives with references on integers Fixes rust-lang#5328
This will allow you to use the
+
operator to add together any twoOptions, assuming that the contents of each Option likewise implement
+
. So Some(4) + Some(1) == Some(5), and adding with None leaves theother value unchanged.
This might be monoidic? I don't know what that word means!