mirror of
https://github.com/correl/elm.git
synced 2024-11-24 11:09:56 +00:00
40 lines
702 B
Elm
40 lines
702 B
Elm
module GradeSchool exposing (..)
|
|
|
|
import Dict exposing (..)
|
|
|
|
|
|
type alias Grade =
|
|
Int
|
|
|
|
|
|
type alias Student =
|
|
String
|
|
|
|
|
|
type alias School =
|
|
Dict Int (List Student)
|
|
|
|
|
|
empty : School
|
|
empty =
|
|
Dict.empty
|
|
|
|
|
|
addStudent : Grade -> Student -> School -> School
|
|
addStudent grade student school =
|
|
Dict.insert grade (List.sort (student :: (studentsInGrade grade school))) school
|
|
|
|
|
|
studentsInGrade : Grade -> School -> List Student
|
|
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 Tuple.first
|