@@ -285,7 +285,7 @@ testArray = do
285
285
assert $ A .group' [1 , 2 , 2 , 3 , 3 , 3 , 1 ] == [1 :| [1 ], 2 :| [2 ], 3 :| [3 , 3 ]]
286
286
287
287
log " groupBy should group consecutive equal elements into arrays based on an equivalence relation"
288
- assert $ A .groupBy (\x y -> odd x && odd y) [1 , 1 , 2 , 2 , 3 , 5 ] == [1 :| [1 ], NE .singleton 2 , NE .singleton 2 , 3 :| [5 ]]
288
+ assert $ A .groupBy eqParity [1 , 1 , 2 , 2 , 3 , 5 , 4 ] == [1 :| [1 ], 2 :| [ 2 ] , 3 :| [5 ], NE .singleton 4 ]
289
289
290
290
log " nub should remove duplicate elements from the list, keeping the first occurence"
291
291
assert $ A .nub [1 , 2 , 2 , 3 , 4 , 1 ] == [1 , 2 , 3 , 4 ]
@@ -365,6 +365,11 @@ odd n = n `mod` 2 /= zero
365
365
doubleAndOrig :: Int -> Array Int
366
366
doubleAndOrig x = [x * 2 , x]
367
367
368
+ -- | An equivalence relation on integers. This relation splits the integers
369
+ -- | into two equivalence classes: odds and evens.
370
+ eqParity :: Int -> Int -> Boolean
371
+ eqParity x y = x `mod` 2 == y `mod` 2
372
+
368
373
data Replicated a = Replicated Int a
369
374
370
375
instance foldableReplicated :: Foldable Replicated where
0 commit comments