Skip to content

Commit 0cd9ba1

Browse files
authored
Merge pull request #24 from purescript/eq-ord-1
Add `Eq1` and `Ord1` instances
2 parents dca906b + b66f07b commit 0cd9ba1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-foldable-traversable": "^2.0.0"
20+
"purescript-foldable-traversable": "^2.0.0",
21+
"purescript-prelude": "^2.4.0"
2122
}
2223
}

src/Data/Either.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import Control.Extend (class Extend)
88
import Data.Bifoldable (class Bifoldable)
99
import Data.Bifunctor (class Bifunctor)
1010
import Data.Bitraversable (class Bitraversable)
11+
import Data.Eq (class Eq1)
1112
import Data.Foldable (class Foldable)
1213
import Data.Functor.Invariant (class Invariant, imapF)
1314
import Data.Monoid (mempty)
15+
import Data.Ord (class Ord1)
1416
import Data.Traversable (class Traversable)
1517

1618
-- | The `Either` type is used to represent a choice between two types of value.
@@ -164,13 +166,17 @@ instance showEither :: (Show a, Show b) => Show (Either a b) where
164166
-- | types the `Either` can contain.
165167
derive instance eqEither :: (Eq a, Eq b) => Eq (Either a b)
166168

169+
instance eq1Either :: Eq a => Eq1 (Either a) where eq1 = eq
170+
167171
-- | The `Ord` instance allows `Either` values to be compared with
168172
-- | `compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for
169173
-- | both types the `Either` can contain.
170174
-- |
171175
-- | Any `Left` value is considered to be less than a `Right` value.
172176
derive instance ordEither :: (Ord a, Ord b) => Ord (Either a b)
173177

178+
instance ord1Either :: Ord a => Ord1 (Either a) where compare1 = compare
179+
174180
instance boundedEither :: (Bounded a, Bounded b) => Bounded (Either a b) where
175181
top = Right top
176182
bottom = Left bottom

0 commit comments

Comments
 (0)