export function maxByOrNull(value: Iterable, transform: (it: T) => number): T | null { let maxIt!: T; let max!: number; let found = false; for (const it of value) { const val = transform(it); if (found && val <= max) continue; maxIt = it; max = val; found = true; } if (!found) return null; return maxIt; }