module Music.Theory.Ord where
ord_to_int :: Ordering -> Int
ord_to_int = fromEnum
int_to_ord :: Int -> Ordering
int_to_ord = toEnum
ord_invert :: Ordering -> Ordering
ord_invert x =
case x of
LT -> GT
EQ -> EQ
GT -> LT
order_pair :: Ordering -> (t,t) -> (t,t)
order_pair o (x,y) =
case o of
LT -> (x,y)
EQ -> (x,y)
GT -> (y,x)
sort_pair :: (t -> t -> Ordering) -> (t,t) -> (t,t)
sort_pair fn (x,y) = order_pair (fn x y) (x,y)
sort_pair_m :: (t -> t -> Maybe Ordering) -> (t,t) -> Maybe (t,t)
sort_pair_m fn (x,y) = fmap (`order_pair` (x,y)) (fn x y)