I am writing Haskell solver for simple board game. I have this function:
bestMove :: Board -> (Int,Int)
bestMove brd = minimumBy (comparing $ length.choices brd) (remaining brd)
Basically bestMove is a move which leaves the smallest amount of choices out of remaining moves. I know however that no element leaves less than one choice. How do I write this function to terminate searching for minimum if such a move is found ?
In other words I want a function which returns minimum or first encountered element which is small enough (without traversing rest of the list).
It's my first Haskell program so it's probably very basic. It's a backtracking solver so not traversing whole list in a function which is called millions of times is important.