@@ -2,9 +2,11 @@ module Test.Data.List (testList) where
2
2
3
3
import Prelude
4
4
5
+ import Data.Array as Array
5
6
import Data.Foldable (foldMap , foldl )
6
7
import Data.FoldableWithIndex (foldMapWithIndex , foldlWithIndex , foldrWithIndex )
7
- import Data.List (List (..), (..), stripPrefix , Pattern (..), length , range , foldM , unzip , zip , zipWithA , zipWith , intersectBy , intersect , (\\), deleteBy , delete , unionBy , union , nubBy , nub , group , groupAll , groupBy , groupAllBy , partition , span , dropWhile , drop , dropEnd , takeWhile , take , takeEnd , sortBy , sort , catMaybes , mapMaybe , filterM , filter , concat , concatMap , reverse , alterAt , modifyAt , updateAt , deleteAt , insertAt , findLastIndex , findIndex , elemLastIndex , elemIndex , (!!), uncons , unsnoc , init , tail , last , head , insertBy , insert , snoc , null , singleton , fromFoldable , transpose , mapWithIndex , (:))
8
+ import Data.Function (on )
9
+ import Data.List (List (..), Pattern (..), alterAt , catMaybes , concat , concatMap , delete , deleteAt , deleteBy , drop , dropEnd , dropWhile , elemIndex , elemLastIndex , filter , filterM , findIndex , findLastIndex , foldM , fromFoldable , group , groupAll , groupAllBy , groupBy , head , init , insert , insertAt , insertBy , intersect , intersectBy , last , length , mapMaybe , mapWithIndex , modifyAt , nub , nubBy , nubByEq , nubEq , null , partition , range , reverse , singleton , snoc , sort , sortBy , span , stripPrefix , tail , take , takeEnd , takeWhile , transpose , uncons , union , unionBy , unsnoc , unzip , updateAt , zip , zipWith , zipWithA , (!!), (..), (:), (\\))
8
10
import Data.List.NonEmpty as NEL
9
11
import Data.Maybe (Maybe (..), isNothing , fromJust )
10
12
import Data.Monoid.Additive (Additive (..))
@@ -37,7 +39,7 @@ testList = do
37
39
assert $ (range 0 5 ) == l [0 , 1 , 2 , 3 , 4 , 5 ]
38
40
assert $ (range 2 (-3 )) == l [2 , 1 , 0 , -1 , -2 , -3 ]
39
41
40
- log " replicate should produce an list containg an item a specified number of times"
42
+ log " replicate should produce an list containing an item a specified number of times"
41
43
assert $ replicate 3 true == l [true , true , true ]
42
44
assert $ replicate 1 " foo" == l [" foo" ]
43
45
assert $ replicate 0 " foo" == l []
@@ -281,12 +283,19 @@ testList = do
281
283
assert $ partitioned.yes == l [5 , 3 , 4 ]
282
284
assert $ partitioned.no == l [1 , 2 ]
283
285
284
- log " nub should remove duplicate elements from the list, keeping the first occurence "
286
+ log " nub should remove duplicate elements from the list, keeping the first occurrence "
285
287
assert $ nub (l [1 , 2 , 2 , 3 , 4 , 1 ]) == l [1 , 2 , 3 , 4 ]
286
288
287
289
log " nubBy should remove duplicate items from the list using a supplied predicate"
288
- let nubPred = \x y -> if odd x then false else x == y
289
- assert $ nubBy nubPred (l [1 , 2 , 2 , 3 , 3 , 4 , 4 , 1 ]) == l [1 , 2 , 3 , 3 , 4 , 1 ]
290
+ let nubPred = compare `on` Array .length
291
+ assert $ nubBy nubPred (l [[1 ],[2 ],[3 ,4 ]] ) == l [[1 ],[3 ,4 ]]
292
+
293
+ log " nubEq should remove duplicate elements from the list, keeping the first occurrence"
294
+ assert $ nubEq (l [1 , 2 , 2 , 3 , 4 , 1 ]) == l [1 , 2 , 3 , 4 ]
295
+
296
+ log " nubByEq should remove duplicate items from the list using a supplied predicate"
297
+ let mod3eq = eq `on` \n -> mod n 3
298
+ assert $ nubByEq mod3eq (l [1 , 3 , 4 , 5 , 6 ]) == l [1 , 3 , 5 ]
290
299
291
300
log " union should produce the union of two lists"
292
301
assert $ union (l [1 , 2 , 3 ]) (l [2 , 3 , 4 ]) == l [1 , 2 , 3 , 4 ]
0 commit comments