diff options
-rw-r--r-- | src/Candidate.hs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Candidate.hs b/src/Candidate.hs index 21f9736..e92fd05 100644 --- a/src/Candidate.hs +++ b/src/Candidate.hs @@ -59,7 +59,7 @@ readCandidates inputFile state = do if (Either.isRight t1) && (Maybe.isJust t2) then readFunc (t3:r) tx else readFunc r tx - raw <- readFunc [] e >>= return . (List.sort) + raw <- readFunc [] e >>= return . (List.sortBy candRecComp) IO.hClose h return (makeAboveBallot raw, makeBelowBallot raw) @@ -67,6 +67,18 @@ readCandidates inputFile state = do +-- assumes there are at least two items in each list +-- see the above function for the things it gets applied on for why +candRecComp :: [String] -> [String] -> Ordering +candRecComp a b = + let lenResult = compare (length (head a)) (length (head b)) + in if (lenResult == EQ) + then compare (take 2 a) (take 2 b) + else lenResult + + + + -- very hacky, pls revise makeAboveBallot :: [[String]] -> AboveLineBallot makeAboveBallot input = |