refactor: make ExamOccurrenceCapacity a newtype
use pattern synonyms for convenience, so usage doesn't change
This commit is contained in:
parent
ae3e1b6266
commit
b5ee9f2c05
@ -19,7 +19,7 @@ module Model.Types.Exam
|
|||||||
, _examOccurrenceMappingRule
|
, _examOccurrenceMappingRule
|
||||||
, _examOccurrenceMappingMapping
|
, _examOccurrenceMappingMapping
|
||||||
, traverseExamOccurrenceMapping
|
, traverseExamOccurrenceMapping
|
||||||
, ExamOccurrenceCapacity(..)
|
, ExamOccurrenceCapacity(.., Unrestricted, Restricted)
|
||||||
, _examOccurrenceCapacityIso
|
, _examOccurrenceCapacityIso
|
||||||
, ExamGrade(..)
|
, ExamGrade(..)
|
||||||
, numberGrade
|
, numberGrade
|
||||||
@ -231,15 +231,16 @@ traverseExamOccurrenceMapping = _examOccurrenceMappingMapping . iso Map.toList (
|
|||||||
--
|
--
|
||||||
-- Maybe doesn't work, because the 'Ord' instance puts 'Nothing' below 0
|
-- Maybe doesn't work, because the 'Ord' instance puts 'Nothing' below 0
|
||||||
-- instead of above every other number.
|
-- instead of above every other number.
|
||||||
data ExamOccurrenceCapacity = Unrestricted | Restricted Natural
|
newtype ExamOccurrenceCapacity = EOCapacity (Maybe Natural)
|
||||||
deriving (Show, Eq)
|
deriving stock (Show)
|
||||||
|
deriving (Eq, Ord) via (NTop (Maybe Natural))
|
||||||
|
|
||||||
-- | Unrestricted is bigger then everything else, otherwise use instance from 'Natural'.
|
pattern Unrestricted :: ExamOccurrenceCapacity
|
||||||
instance Ord ExamOccurrenceCapacity where
|
pattern Unrestricted = EOCapacity Nothing
|
||||||
compare Unrestricted Unrestricted = EQ
|
pattern Restricted :: Natural -> ExamOccurrenceCapacity
|
||||||
compare Unrestricted (Restricted _n) = GT
|
pattern Restricted n = EOCapacity (Just n)
|
||||||
compare (Restricted _n) Unrestricted = LT
|
|
||||||
compare (Restricted a) (Restricted b) = compare a b
|
{-# COMPLETE Unrestricted, Restricted #-}
|
||||||
|
|
||||||
-- | Addition monoid with 'Unrestricted' interpreted as infinity.
|
-- | Addition monoid with 'Unrestricted' interpreted as infinity.
|
||||||
instance Semigroup ExamOccurrenceCapacity where
|
instance Semigroup ExamOccurrenceCapacity where
|
||||||
|
|||||||
Reference in New Issue
Block a user