elm/exercises/grade-school/GradeSchool.example

41 lines
694 B
Text
Raw Normal View History

module GradeSchool exposing (..)
2015-10-14 19:02:13 +00:00
import Dict exposing (..)
type alias Grade =
Int
2015-10-14 19:02:13 +00:00
type alias Student =
String
type alias School =
Dict Int (List Student)
2015-10-14 19:02:13 +00:00
empty : School
empty =
Dict.empty
2015-10-14 19:02:13 +00:00
addStudent : Grade -> Student -> School -> School
2015-10-14 19:02:13 +00:00
addStudent grade student school =
Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school
2015-10-14 19:02:13 +00:00
studentsInGrade : Grade -> School -> List Student
2015-10-14 19:02:13 +00:00
studentsInGrade grade school =
case (Dict.get grade school) of
Just list ->
list
Nothing ->
[]
allStudents : School -> List ( Grade, List Student )
allStudents school =
Dict.toList school |> List.sortBy fst