Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Created April 6, 2016 14:49
Show Gist options
  • Save ccapndave/7ea87b5da653a6eaf07dc7b2a563ee20 to your computer and use it in GitHub Desktop.
Save ccapndave/7ea87b5da653a6eaf07dc7b2a563ee20 to your computer and use it in GitHub Desktop.
{-| Calculate a score from the model
-}
score : Model -> ExerciseMark
score model =
let
-- Fold over the questions, accumulating a mark
score' : Exercise -> Array QuestionState -> ExerciseMark
score' exercise questionStates =
let
-- The folding function
acc : (Question, QuestionState) -> ExerciseMark -> ExerciseMark
acc (question, questionState) exerciseMark =
let
-- Get the score and update the mark
score = QuestionDelegate.scoreQuestion question questionState
in
ExerciseMark.updateWithScore score exerciseMark
in
Array.Extra.zip exercise.questions questionStates
|> Array.foldr acc ExerciseMark.new
in
model.exercise
|> Maybe.map (\e -> score' e model.questionStates)
|> Maybe.withDefault ExerciseMark.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment