Sha256: 9a36f14e25a775e09ea7e91ae835b861cb1a1ae3fd33bbfc15bb741ed4058626
Contents?: true
Size: 655 Bytes
Versions: 396
Compression:
Stored size: 655 Bytes
Contents
module School (School, empty, grade, add, sorted) where import qualified Data.Map as M import qualified Data.Set as S import Control.Arrow (second) type Grade = Int type Student = String newtype School = School { unSchool :: M.Map Grade (S.Set Student) } empty :: School empty = School M.empty sorted :: School -> [(Grade, [Student])] sorted = map (second S.toAscList) . M.toAscList . unSchool grade :: Grade -> School -> [Student] grade gradeNum = S.toAscList . M.findWithDefault S.empty gradeNum . unSchool add :: Grade -> Student -> School -> School add gradeNum student = School . M.insertWith S.union gradeNum (S.singleton student) . unSchool
Version data entries
396 entries across 396 versions & 1 rubygems