-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat - Enum.min_max sorter #14690
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 - Enum.min_max sorter #14690
Conversation
lib/elixir/lib/enum.ex
Outdated
If multiple elements are considered maximal or minimal, the first one | ||
that was found is returned. |
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.
If multiple elements are considered maximal or minimal, the first one | |
that was found is returned. | |
By default, the comparison is done with the `<` sorter function, | |
as the function must not return true for equal elements. |
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.
I have updated the text here. The code won't work if it the sorting function returns equal. Can you please apply it accordingly to min_max_by
? Then we are good to go.
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.
done
💚 💙 💜 💛 ❤️ |
""" | ||
@spec min_max(t, (-> empty_result)) :: {element, element} | empty_result | ||
@spec min_max(t, (element, element -> boolean) | module()) :: | ||
{element, element} | empty_result | ||
when empty_result: any | ||
@spec min_max( | ||
t, | ||
(element, element -> boolean) | module(), | ||
(-> empty_result) | ||
) :: {element, element} | empty_result | ||
when empty_result: any |
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.
Calling Enum.min_max/2
with a 0-arity anonymous function is still valid (like in the last hexdoc example) but it was removed from this function spec, shouldn't it still be documented?
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.
It seems we don't docuyment on the other ones but we should probably be consistent and document on them all.
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.
closes #14684
based on the logic of min_max_by