aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Round.elm
blob: 4586ede0e95f080b6e6ac7b49b093564944d45ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Model.Round
  ( Round
  , maybeBestRound
  ) where

import List
import Time exposing (Time)

type alias Round =
  { duration : Time
  , score : Int
  }

maybeBestRound : List Round -> Maybe Round
maybeBestRound rounds =
  let orderedRounds =
        rounds
          |> List.sortWith roundOrder
          |> List.reverse
  in  case orderedRounds of
        [] -> Nothing
        best :: _ -> Just best

roundOrder : Round -> Round -> Order
roundOrder round1 round2 =
  if round1.score == round2.score
    then
      compare round2.duration round1.duration
    else
      compare round1.score round2.score