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 =
|
2016-06-19 21:46:13 +00:00
|
|
|
Int
|
2015-10-14 19:02:13 +00:00
|
|
|
|
|
|
|
|
2016-03-17 01:16:54 +00:00
|
|
|
type alias Student =
|
2016-06-19 21:46:13 +00:00
|
|
|
String
|
2016-03-17 01:38:51 +00:00
|
|
|
|
|
|
|
|
2016-03-17 01:16:54 +00:00
|
|
|
type alias School =
|
2016-06-19 21:46:13 +00:00
|
|
|
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-06-19 21:46:13 +00:00
|
|
|
Dict.empty
|
2016-03-17 01:38:51 +00:00
|
|
|
|
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 =
|
2016-06-19 21:46:13 +00:00
|
|
|
Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school
|
2015-10-14 19:02:13 +00:00
|
|
|
|
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 =
|
2016-06-19 21:46:13 +00:00
|
|
|
case (Dict.get grade school) of
|
|
|
|
Just list ->
|
|
|
|
list
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2016-06-19 21:46:13 +00:00
|
|
|
Nothing ->
|
|
|
|
[]
|
2016-03-17 01:16:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
allStudents : School -> List ( Grade, List Student )
|
|
|
|
allStudents school =
|
2016-12-17 22:15:34 +00:00
|
|
|
Dict.toList school |> List.sortBy Tuple.first
|