Created
April 6, 2016 14:49
-
-
Save ccapndave/7ea87b5da653a6eaf07dc7b2a563ee20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-| 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