2016-03-17 01:38:35 +00:00
|
|
|
module GradeSchool (..) where
|
2015-10-14 19:02:13 +00:00
|
|
|
|
|
|
|
import Dict exposing (..)
|
|
|
|
import Result exposing (toMaybe)
|
2016-03-17 01:38:51 +00:00
|
|
|
|
|
|
|
|
2015-10-14 19:02:13 +00:00
|
|
|
-- TODO: implement these classes
|
|
|
|
-- type Grade = Int
|
|
|
|
-- type Student = String
|
|
|
|
-- type School = Dict Int List String
|
|
|
|
|
|
|
|
|
2016-03-17 01:38:51 +00:00
|
|
|
schoolFromList : List ( Int, String ) -> Dict Int (List String)
|
|
|
|
schoolFromList schoolList =
|
|
|
|
List.foldl
|
|
|
|
(\tuple -> \dict -> addStudent (fst tuple) (snd tuple) dict)
|
|
|
|
newSchool
|
|
|
|
schoolList
|
|
|
|
|
|
|
|
|
|
|
|
schoolToList : Dict Int (List String) -> List ( Int, List String )
|
|
|
|
schoolToList school =
|
|
|
|
Dict.toList school
|
|
|
|
|
2015-10-14 19:02:13 +00:00
|
|
|
|
|
|
|
newSchool : Dict Int (List String)
|
2016-03-17 01:38:51 +00:00
|
|
|
newSchool =
|
|
|
|
Dict.empty
|
|
|
|
|
2015-10-14 19:02:13 +00:00
|
|
|
|
|
|
|
addStudent : Int -> String -> Dict Int (List String) -> Dict Int (List String)
|
|
|
|
addStudent grade student school =
|
|
|
|
Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school
|
|
|
|
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2015-10-14 19:02:13 +00:00
|
|
|
gradeWithStudents : Int -> List String -> Dict Int (List String)
|
2016-03-17 01:38:51 +00:00
|
|
|
gradeWithStudents grade students =
|
|
|
|
Dict.singleton grade (List.sort students)
|
|
|
|
|
2015-10-14 19:02:13 +00:00
|
|
|
|
|
|
|
studentsInGrade : Int -> Dict Int (List String) -> List String
|
|
|
|
studentsInGrade grade school =
|
|
|
|
case (Dict.get grade school) of
|
2016-03-17 01:38:51 +00:00
|
|
|
Just list ->
|
|
|
|
list
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
[]
|