Refactor findMax to more closely match Rust

This commit is contained in:
George Thomas 2025-12-19 16:22:26 +00:00
parent 4a3506a58d
commit 2cf462ad9d

View File

@ -37,4 +37,4 @@ maxBatteries n0 (Bank bs0) = flip unfoldrM (n0, toList bs0) \case
-- returns the leftmost element in case of a tie
findMax :: (Ord a) => NonEmpty a -> (Int, a)
findMax = foldl1' (\m x -> if snd x > snd m then x else m) . NE.zip (0 :| [1 ..])
findMax = maximumBy (comparing snd) . NE.reverse . NE.zip (0 :| [1 ..])