Skip to content

Commit

Permalink
Document min/max functions throw with empty lists
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed Aug 12, 2024
1 parent 0e85315 commit 1052605
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/compareEachWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { MergeComparatorInputs } from "./private/types";
* Creates a comparator that compares iterables (e.g. arrays) in lexicographic
* order.
*
* You must provide a comparator (such as `naturalOrder`) for comparing
* You must provide a comparator (such as {@link naturalOrder}) for comparing
* corresponding pairs of elements. You can provide multiple comparator
* arguments, which are combined similarly to {@link compareWith}.
*
Expand Down
4 changes: 2 additions & 2 deletions src/minmax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("max", () => {
expect(max(2, 3, 1)).toBe(3);
});

it("does not type-check with zero arguments", () => {
it("throws TypeError with zero arguments", () => {
// @ts-expect-error
expect(() => max()).toThrow(TypeError);
});
Expand All @@ -26,7 +26,7 @@ describe("min", () => {
expect(min(2, 1, 3)).toBe(1);
});

it("does not type-check with zero arguments", () => {
it("throws TypeError with zero arguments", () => {
// @ts-expect-error
expect(() => min()).toThrow(TypeError);
});
Expand Down
4 changes: 4 additions & 0 deletions src/minmax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { naturalOrder } from "./comparators";
*
* @param values values to compare
* @returns the smallest value
* @throws {TypeError} thrown if `values` is empty
*/
export function min<T>(values: T[]): T;

Expand Down Expand Up @@ -44,6 +45,7 @@ export function min<T>(...args: T[] | [T[]]): T {
*
* @param values values to compare
* @returns the largest value
* @throws {TypeError} thrown if `values` is empty
*/
export function max<T>(values: T[]): T;

Expand Down Expand Up @@ -73,6 +75,7 @@ export function max<T>(...args: T[] | [T[]]): T {
* @param values the list of values to compare
* @param comparator compares the values
* @returns the smallest value
* @throws {TypeError} thrown if `values` is empty
*/
export function minWith<T>(values: T[], comparator: Comparator<T>): T {
return values.reduce(minReducer(comparator));
Expand All @@ -84,6 +87,7 @@ export function minWith<T>(values: T[], comparator: Comparator<T>): T {
* @param values the list of values to compare
* @param comparator compares the values
* @returns the largest value
* @throws {TypeError} thrown if `values` is empty
*/
export function maxWith<T>(values: T[], comparator: Comparator<T>): T {
return values.reduce(maxReducer(comparator));
Expand Down

0 comments on commit 1052605

Please sign in to comment.