Given students' names along with the grade that they are in, create a roster for the school.
In the end, you should be able to:
Note that all our students only have one name. (It's a small town, what do you want?)
Did you get the tests passing and the code clean? If you want to, these are some additional things you could try:
Then please share your thoughts in a comment on the submission. Did this experiment make the code better? Worse? Did you learn anything from it?
Refer to the Installing Elm page for information about installing elm.
The first time you start an exercise, you'll need to ensure you have the appropriate dependencies installed. Thankfully, Elm makes that easy for you and will install dependencies when you try to run tests or build the code.
Execute the tests with:
Automatically run tests again when you save changes:
$ elm-test --watch
As you work your way through the test suite, be sure to remove the
calls from each test until you get them all passing!
A pairing session with Phil Battos at gSchool http://gschool.it
It is possible to submit an incomplete solution so you can see how others have completed the exercise.
module Tests exposing (tests) import Expect import GradeSchool exposing (addStudent, allStudents, studentsInGrade) import Test exposing (..) tests : Test tests = describe "GradeSchool" [ test "add student" <| \() -> Expect.equal [ "Aimee" ] (GradeSchool.empty |> addStudent 2 "Aimee" |> studentsInGrade 2 ) , skip <| test "add more students in same class" <| \() -> Expect.equal [ "Blair", "James", "Paul" ] (GradeSchool.empty |> addStudent 2 "James" |> addStudent 2 "Blair" |> addStudent 2 "Paul" |> studentsInGrade 2 ) , skip <| test "add students to different grades" <| \() -> Expect.equal [ [ "Chelsea" ], [ "Logan" ] ] (let school = GradeSchool.empty |> addStudent 3 "Chelsea" |> addStudent 7 "Logan" in [ studentsInGrade 3 school, studentsInGrade 7 school ] ) , skip <| test "get students in a grade" <| \() -> Expect.equal [ "Bradley", "Franklin" ] (GradeSchool.empty |> addStudent 5 "Franklin" |> addStudent 5 "Bradley" |> addStudent 1 "Jeff" |> studentsInGrade 5 ) , skip <| test "get all students in the school" <| \() -> Expect.equal [ ( 3, [ "Kyle" ] ), ( 4, [ "Christopher", "Jennifer" ] ), ( 6, [ "Kareem" ] ) ] (GradeSchool.empty |> addStudent 4 "Jennifer" |> addStudent 6 "Kareem" |> addStudent 4 "Christopher" |> addStudent 3 "Kyle" |> allStudents ) , skip <| test "get students in a non-existent grade" <| \() -> Expect.equal  (studentsInGrade 1 GradeSchool.empty) ]
module GradeSchool exposing (addStudent, allStudents, empty, studentsInGrade) import Dict exposing (Dict) type alias Grade = Int type alias Student = String type alias School = Dict Grade (List Student) empty : School empty = Dict.empty addStudent : Grade -> Student -> School -> School addStudent grade student school = let addName : Maybe (List Student) -> Maybe (List Student) addName names = case names of Just students -> Just (student :: students) Nothing -> Just [ student ] in school |> Dict.update grade addName studentsInGrade : Grade -> School -> List Student studentsInGrade grade school = let allStudentsInGrade = Dict.get grade school in case allStudentsInGrade of Just students -> List.sort students Nothing ->  allStudents : School -> List ( Grade, List Student ) allStudents school = Dict.toList school
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.