-
Notifications
You must be signed in to change notification settings - Fork 124
feat: add @cmp.(max|min)imum_by_key
#1162
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
|
Pull Request Test Coverage Report for Build 5865Details
💛 - 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 |
39dfd58
to
1b3921b
Compare
@math.(max|min)imum_by_key
@cmp.(max|min)imum_by_key
@bobzhang Moved to |
4486855
to
4228c53
Compare
4228c53
to
635ba38
Compare
Mirrors Rust's max_by_key and min_by_key functions.