-
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
feat: add @math.(max|min)imum_by_key
#1162
base: main
Are you sure you want to change the base?
Conversation
Observations and Suggestions
Summary
These suggestions aim to enhance code readability, maintainability, and ensure consistent practices across the codebase. |
Pull Request Test Coverage Report for Build 3775Details
💛 - Coveralls |
c02892e
to
f8c47d1
Compare
Do we need these tiny functions? I think they are not particularly useful |
I think it makes some business logic more readable, like the example below: Beforelet span l0 l1 =
let first_byte, first_line =
if l0.first_byte < l1.first_byte
then l0.first_byte, l0.first_line
else l1.first_byte, l1.first_line
in
let last_byte, last_line, file =
if l0.last_byte < l1.last_byte
then l1.last_byte, l1.last_line, l1.file
else l0.last_byte, l0.last_line, l0.file
in
v ~file ~first_byte ~first_line ~last_byte ~last_line Afterpub fn TextLoc::span(self : TextLoc, other : TextLoc) -> TextLoc {
let { first_byte, first_line, .. } = minimum_by_key(other, self, fn(it) { it.first_byte })
let { file, last_byte, last_line, .. } = maximum_by_key(other, self, fn(it) { it.last_byte })
{ file, first_byte, last_byte, first_line, last_line }
} |
Python does the same thing with the Similarly, in the OCaml ecosystem, a slightly more heavyweight solution is available via |
f8c47d1
to
9b3bbb3
Compare
@rami3l I think it is okay to have this util, but it does not belong to |
@bobzhang Thanks for the feedback! In that case, however, should PS: I believe the |
Mirrors Rust's max_by_key and min_by_key functions.
New Functions
math/algebraic.mbt
: Addedmaximum_by_key
function to return the element that gives the maximum value from the specified function.math/algebraic.mbt
: Addedminimum_by_key
function to return the element that gives the minimum value from the specified function.Tests
math/algebraic_test.mbt
: Added tests for themaximum_by_key
and theminimum_by_key
functions to verify their behavior with positive and negative integers.Interface
math/math.mbti
: Updated the module interface to include the newmaximum_by_key
andminimum_by_key
functions.