Skip to content

feat(math): add Median, MedianBy, and MedianByErr#872

Open
walle250ai wants to merge 1 commit into
samber:masterfrom
walle250ai:master
Open

feat(math): add Median, MedianBy, and MedianByErr#872
walle250ai wants to merge 1 commit into
samber:masterfrom
walle250ai:master

Conversation

@walle250ai
Copy link
Copy Markdown

Summary

  • Add Median[T] — returns the median of a collection; sorts a copy, returns zero value for empty input
  • Add MedianBy[T, R] — projects each element via iteratee, then computes median on the projected values
  • Add MedianByErr[T, R] — same as MedianBy but short-circuits on the first iteratee error without sorting a partial result

All three follow the established Mean / MeanBy / MeanByErr conventions exactly: same generic constraints, same empty-collection semantics, same integer-truncation behavior for even-length slices.

Test plan

  • TestMedian: empty, odd-length, even-length, float cases
  • TestMedianBy: mirrors TestMedian with identity iteratee
  • TestMedianByErr: table-driven normal path (8 cases) + error path (3 cases) with iteratee call-count assertions verifying early exit

🤖 Generated with Claude Code

Complete the statistical trio alongside Mean and Mode. Median returns
the middle value of a sorted copy of the collection; even-length input
averages the two middle elements with the same integer-truncation
semantics as Mean. MedianByErr short-circuits on the first iteratee
error without sorting a partial result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant