Skip to content
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

[stdlib] Median #1450

Closed
wants to merge 1 commit into from
Closed

[stdlib] Median #1450

wants to merge 1 commit into from

Conversation

benrimmington
Copy link
Contributor

This proposal would add a global median function to the standard library.

Swift-evolution thread: Pitch

@benrimmington benrimmington added the standard library addition Additive changes to the standard library label Sep 29, 2021
@tkremenek
Copy link
Member

The core team did a preflight discussion of this proposal to determine if this should move to the review stage. That discussion raised some concerns:

  • The proposal adds a function that takes precisely three arguments. While the semantics of median is evident in this case (i.e., there always is a "center" value), there was general skepticism that such a function would add much value to the Standard Library.

  • A more general API — that takes (say) a variable number of values — might have higher utility, but also begets the question of how to define the median for different types. In a statistical context, the median of an even number of values is the average of the two central values. In many programming contexts, however, it is important that the returned value be one of the original elements. The latter definition can also be applied to collections of non-numerical types. For this to be available on non-numeric types, there would need to be a well-defined answer. For example, what should the result of ["a","b","c","d"].median be?

  • The core team wondered if this function would better fit with a family of numerical or statistical APIs. Such packaging of the API would better capture the use case for median and provide precise semantics for the odd and even number of values cases.

Based on these concerns, the core team does not believe the proposal should move forward with review. Thank you for taking the time to draft it up.

@tkremenek tkremenek closed this Nov 5, 2021
@benrimmington benrimmington deleted the median branch November 5, 2021 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library addition Additive changes to the standard library
Projects
None yet
2 participants