import Comparator from "./Comparator"; import nativeOrdering from "./nativeOrdering"; export default ( vals: Iterable, ifEmpty: () => T, comparator: Comparator = nativeOrdering as any ): T => { let max: T; let set = false; for (const val of vals) { // @ts-ignore Use before assignment. if (!set || comparator(val, max) > 0) { max = val; } set = true; } if (!set) { return ifEmpty(); } // @ts-ignore Use before assignment. return max; };