@@ -40,6 +40,9 @@ import Rel8.Table.Eq ( EqTable )
4040import Rel8.Type.Ord ( DBOrd )
4141
4242
43+-- | The class of 'Table's that can be ordered. Ordering on tables is defined
44+-- by their lexicographic ordering of all columns, so this class means "all
45+-- columns in a 'Table' have an instance of 'DBOrd'".
4346type OrdTable :: Type -> Constraint
4447class
4548 ( EqTable a
@@ -52,6 +55,8 @@ instance
5255instance {-# OVERLAPPING #-} OrdTable Opaque
5356
5457
58+-- | Test if one 'Table' sorts before another. Corresponds to comparing all
59+-- columns with '<'.
5560(<:) :: forall a. OrdTable a => a -> a -> Expr Bool
5661(toColumns -> as) <: (toColumns -> bs) =
5762 foldr @[] go false $ getConst $ htabulateA $ \field ->
@@ -67,6 +72,8 @@ instance {-# OVERLAPPING #-} OrdTable Opaque
6772infix 4 <:
6873
6974
75+-- | Test if one 'Table' sorts before, or is equal to, another. Corresponds to
76+-- comparing all columns with '<='.
7077(<=:) :: forall a. OrdTable a => a -> a -> Expr Bool
7178(toColumns -> as) <=: (toColumns -> bs) =
7279 foldr @[] go true $ getConst $ htabulateA $ \field ->
@@ -82,6 +89,8 @@ infix 4 <:
8289infix 4 <=:
8390
8491
92+-- | Test if one 'Table' sorts after another. Corresponds to comparing all
93+-- columns with '>'.
8594(>:) :: forall a. OrdTable a => a -> a -> Expr Bool
8695(toColumns -> as) >: (toColumns -> bs) =
8796 foldr @[] go false $ getConst $ htabulateA $ \field ->
@@ -97,6 +106,8 @@ infix 4 <=:
97106infix 4 >:
98107
99108
109+-- | Test if one 'Table' sorts after another. Corresponds to comparing all
110+-- columns with '>='.
100111(>=:) :: forall a. OrdTable a => a -> a -> Expr Bool
101112(toColumns -> as) >=: (toColumns -> bs) =
102113 foldr @[] go true $ getConst $ htabulateA $ \field ->
@@ -112,9 +123,11 @@ infix 4 >:
112123infix 4 >=:
113124
114125
126+-- | Given two 'Table's, return the table that sorts before the other.
115127least :: OrdTable a => a -> a -> a
116128least a b = bool a b (a <: b)
117129
118130
131+-- | Given two 'Table's, return the table that sorts after the other.
119132greatest :: OrdTable a => a -> a -> a
120133greatest a b = bool a b (a >: b)