TU-CSCI2322-FL22 / solver-the-connectors

solver-the-connectors created by GitHub Classroom
0 stars 0 forks source link

Prefer "case" expressions to equality, esp. for multiple equality tests #5

Closed sfogarty closed 1 year ago

sfogarty commented 1 year ago

https://github.com/TU-CSCI2322-FL22/solver-the-connectors/blob/ec3768dbb3f7b8de3314ef33076437f4b7b7cd66/ConnectFour.hs#L44-L48

     mkCol = foldr (\x y -> case findColor brd (cnt, x) of 
                                              Just Red -> 'O':y
                                              Just Black -> 'X':y
                                              Nothing -> '-':y) [] [1..7] 

Even better, multiline functions should probably be defined separately. Also, this could just be a map.

   toColor x = case findColor brd (cnt, x) of 
                                              Just Red -> 'O'
                                              Just Black -> 'X'
                                              Nothing -> '-'
     mkCol = map toColor [1..7]