aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Round.elm
blob: c983839e0d3a29f66946d8d2b25a14bb6700b6e3 (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 exposing
  ( Round
  , maybeBestRound
  )

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