Skip to content

Commit 098009c

Browse files
committed
Add Data.Vector.Generic.eqBy and cmpBy
1 parent be5ecf6 commit 098009c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Data/Vector/Generic.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ module Data.Vector.Generic (
158158

159159
-- ** Comparisons
160160
eq, cmp,
161+
eqBy, cmpBy,
161162

162163
-- ** Show and Read
163164
showsPrec, readPrec,
@@ -2131,6 +2132,11 @@ eq :: (Vector v a, Eq a) => v a -> v a -> Bool
21312132
{-# INLINE eq #-}
21322133
xs `eq` ys = stream xs == stream ys
21332134

2135+
-- | /O(n)/
2136+
eqBy :: (Vector v a, Vector v b) => (a -> b -> Bool) -> v a -> v b -> Bool
2137+
{-# INLINE eqBy #-}
2138+
eqBy e xs ys = Bundle.eqBy e (stream xs) (stream ys)
2139+
21342140
-- | /O(n)/ Compare two vectors lexicographically. All 'Vector' instances are
21352141
-- also instances of 'Ord' and it is usually more appropriate to use those. This
21362142
-- function is primarily intended for implementing 'Ord' instances for new
@@ -2139,6 +2145,10 @@ cmp :: (Vector v a, Ord a) => v a -> v a -> Ordering
21392145
{-# INLINE cmp #-}
21402146
cmp xs ys = compare (stream xs) (stream ys)
21412147

2148+
-- | /O(n)/
2149+
cmpBy :: (Vector v a, Vector v b) => (a -> b -> Ordering) -> v a -> v b -> Ordering
2150+
cmpBy c xs ys = Bundle.cmpBy c (stream xs) (stream ys)
2151+
21422152
-- Show
21432153
-- ----
21442154

0 commit comments

Comments
 (0)