elm/exercises/grade-school/GradeSchool.example.elm

41 lines
702 B
Elm
Raw Permalink 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 =
2016-12-17 22:15:34 +00:00
Dict.toList school |> List.sortBy Tuple.first