2016-05-13 02:26:52 +00:00
|
|
|
module GradeSchool exposing (..)
|
2015-10-14 19:02:13 +00:00
|
|
|
|
|
|
|
import Dict exposing (..)
|
2016-03-17 01:38:51 +00:00
|
|
|
|
|
|
|
|
2016-03-17 01:16:54 +00:00
|
|
|
type alias Grade =
|
|
|
|
Int
|
2015-10-14 19:02:13 +00:00
|
|
|
|
|
|
|
|
2016-03-17 01:16:54 +00:00
|
|
|
type alias Student =
|
|
|
|
String
|
2016-03-17 01:38:51 +00:00
|
|
|
|
|
|
|
|
2016-03-17 01:16:54 +00:00
|
|
|
type alias School =
|
|
|
|
Dict Int (List Student)
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2015-10-14 19:02:13 +00:00
|
|
|
|
2016-03-17 01:16:54 +00:00
|
|
|
empty : School
|
|
|
|
empty =
|
2016-03-17 01:38:51 +00:00
|
|
|
Dict.empty
|
|
|
|
|
2015-10-14 19:02:13 +00:00
|
|
|
|
2016-03-17 01:16:54 +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
|
|
|
|
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2016-03-17 01:16:54 +00:00
|
|
|
studentsInGrade : Grade -> School -> List Student
|
2015-10-14 19:02:13 +00:00
|
|
|
studentsInGrade grade school =
|
|
|
|
case (Dict.get grade school) of
|
2016-03-17 01:38:51 +00:00
|
|
|
Just list ->
|
|
|
|
list
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
[]
|
2016-03-17 01:16:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
allStudents : School -> List ( Grade, List Student )
|
|
|
|
allStudents school =
|
|
|
|
Dict.toList school |> List.sortBy fst
|