@@ -2,9 +2,11 @@ module Test.Data.List (testList) where
22
33import Prelude
44
5+ import Data.Array as Array
56import Data.Foldable (foldMap , foldl )
67import 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 , (!!), (..), (:), (\\))
810import Data.List.NonEmpty as NEL
911import Data.Maybe (Maybe (..), isNothing , fromJust )
1012import Data.Monoid.Additive (Additive (..))
@@ -37,7 +39,7 @@ testList = do
3739 assert $ (range 0 5 ) == l [0 , 1 , 2 , 3 , 4 , 5 ]
3840 assert $ (range 2 (-3 )) == l [2 , 1 , 0 , -1 , -2 , -3 ]
3941
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"
4143 assert $ replicate 3 true == l [true , true , true ]
4244 assert $ replicate 1 " foo" == l [" foo" ]
4345 assert $ replicate 0 " foo" == l []
@@ -281,12 +283,19 @@ testList = do
281283 assert $ partitioned.yes == l [5 , 3 , 4 ]
282284 assert $ partitioned.no == l [1 , 2 ]
283285
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 "
285287 assert $ nub (l [1 , 2 , 2 , 3 , 4 , 1 ]) == l [1 , 2 , 3 , 4 ]
286288
287289 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 ]
290299
291300 log " union should produce the union of two lists"
292301 assert $ union (l [1 , 2 , 3 ]) (l [2 , 3 , 4 ]) == l [1 , 2 , 3 , 4 ]
0 commit comments