Skip to content

Instantly share code, notes, and snippets.

@fotonmoton
Created December 3, 2019 13:03
Show Gist options
  • Save fotonmoton/e474359079d8bc0bded6ab06de39eae3 to your computer and use it in GitHub Desktop.
Save fotonmoton/e474359079d8bc0bded6ab06de39eae3 to your computer and use it in GitHub Desktop.
module GradeSchool
type School = Map<int, string list>
let empty: School = Map.empty
let add student grade school: School =
let addTo school grade students = Map.add grade students school
school
|> Map.tryFind grade
|> Option.defaultValue []
|> List.append [ student ]
|> List.sort
|> addTo school grade
let roster school: string list =
school
|> Map.toList
|> List.collect snd
let grade number school: string list =
school
|> Map.tryFind number
|> Option.defaultValue []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment