-
Notifications
You must be signed in to change notification settings - Fork 94
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 @math.maximum()
and @math.minimum()
#35
Conversation
/// print(@math.maximum(1, 2)) // output: 2 | ||
/// print(@math.maximum(2, 2)) // output: 2 | ||
/// ``` | ||
pub fn maximum[T : Compare](x : T, y : T) -> T { |
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.
The full name maximum
follows the convention in list/list.mbt
:
Line 497 in ad0d7c8
pub fn maximum[T : Compare](self : List[T]) -> T { |
However, I personally prefer max
and min
, thoughts?
math/algebraic.mbt
Outdated
let v1 = 1 | ||
let v2 = 2 | ||
let x1 = "v\(v1)" | ||
let x2 = "v\(v2)" | ||
|
||
// We need another value that `== x2` but not `=== x2` | ||
let x2t = "v\(v2)" | ||
@assertion.assert_is_not(x2, x2t).unwrap() |
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.
Do we have a way to reuse code for testing, without introducing footprints in release builds?
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.
yes, we are working on that.
/// Compares and returns the maximum of two values. | ||
/// | ||
/// Returns the second argument if the comparison determines them to be equal. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// print(@math.maximum(1, 2)) // output: 2 | ||
/// print(@math.maximum(2, 2)) // output: 2 | ||
/// ``` |
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.
About conventions of doc strings:
- I used "Compares" instead of "Compare", while both forms can be found in the code base. I believe it implies "(this function) compares and returns ...".
- I used "Examples" instead of "Example" because I do have multiple examples. I think we should stick with "Examples" (like Rust) across the repo even if it's just a single example.
- I used
@math.maximum
instead of justmaximum
so that users could directly copy it from the documentation and run without errors. - I'm not sure we like the
print(...) // output: ...
style in doc strings, it's incompatible with potential future doc tests. Though,@assertion.assert_eq(@math.maximum(1, 2), 2)
is just too long to read, so I ended up following what the rest of this repo has been doing.
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.
Thanks for the suggestions, about the last one, we will consider generate example based docs directly from test "example"
@math
package (Rust put min and max instd::cmp
though)Ported from muts.