Skip to content

Commit 55537a7

Browse files
order up
1 parent 9facbb9 commit 55537a7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Data/Unfoldable1/Trivial1/Internal.purs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ instance trivial1Semigroup :: Semigroup (Trivial1 a) where
189189
instance trivial1Eq :: Eq a => Eq (Trivial1 a) where
190190
eq = eq1
191191

192-
-- instance trivial1Ord :: Ord a => Ord (Trivial1 a) where
193-
-- compare = compare1
192+
instance trivial1Ord :: Ord a => Ord (Trivial1 a) where
193+
compare = compare1
194194

195195
instance trivial1Eq1 :: Eq1 Trivial1 where
196196
eq1 :: forall a. Eq a => Trivial1 a -> Trivial1 a -> Boolean
@@ -199,5 +199,18 @@ instance trivial1Eq1 :: Eq1 Trivial1 where
199199
eEq1 f b f' b' =
200200
case f b /\ f' b' of
201201
(a /\ Nothing) /\ a' /\ Nothing -> a == a'
202-
(a /\ Just nb) /\ a' /\ Just nb' -> a == a' && eEq1 f nb f' nb'
202+
(a /\ Just nb) /\ a' /\ Just nb'
203+
| a == a' -> eEq1 f nb f' nb' -- && does short circuit but I don't want to count on it
203204
_ -> false
205+
206+
instance trivial1Ord1 :: Ord1 Trivial1 where
207+
compare1 :: forall a. Ord a => Trivial1 a -> Trivial1 a -> Ordering
208+
compare1 t1 = untrivial1 (untrivial1 eCompare1 t1)
209+
where eCompare1 :: forall b b'. Generator1 a b -> b -> Generator1 a b' -> b' -> Ordering
210+
eCompare1 f b f' b' =
211+
case f b /\ f' b' of
212+
(a /\ Nothing) /\ a' /\ Nothing -> a `compare` a'
213+
(a /\ Just nb) /\ a' /\ Just nb'
214+
| a == a' -> eCompare1 f nb f' nb'
215+
_ /\ _ /\ Nothing -> LT
216+
_ /\ _ /\ Just _ -> GT

0 commit comments

Comments
 (0)