@@ -2,8 +2,10 @@ module Test.Data.List.NonEmpty (testNonEmptyList) where
2
2
3
3
import Prelude
4
4
5
+ import Data.Array as Array
5
6
import Data.Foldable (class Foldable , foldM , foldMap , foldl , length )
6
7
import Data.FoldableWithIndex (foldlWithIndex , foldrWithIndex , foldMapWithIndex )
8
+ import Data.Function (on )
7
9
import Data.List as L
8
10
import Data.List.NonEmpty as NEL
9
11
import Data.Maybe (Maybe (..))
@@ -182,12 +184,19 @@ testNonEmptyList = do
182
184
assert $ partitioned.yes == l [5 , 3 , 4 ]
183
185
assert $ partitioned.no == l [1 , 2 ]
184
186
187
+ log " nub should remove duplicate elements from the list, keeping the first occurence"
188
+ assert $ NEL .nub (nel 1 [2 , 2 , 3 , 4 , 1 ]) == nel 1 [2 , 3 , 4 ]
189
+
190
+ log " nubBy should remove duplicate items from the list using a supplied predicate"
191
+ let nubPred = compare `on` Array .length
192
+ assert $ NEL .nubBy nubPred (nel [1 ] [[2 ],[3 ,4 ]] ) == nel [1 ] [[3 ,4 ]]
193
+
185
194
log " nubEq should remove duplicate elements from the list, keeping the first occurence"
186
195
assert $ NEL .nubEq (nel 1 [2 , 2 , 3 , 4 , 1 ]) == nel 1 [2 , 3 , 4 ]
187
196
188
197
log " nubByEq should remove duplicate items from the list using a supplied predicate"
189
- let nubPred = \x y -> if odd x then false else x == y
190
- assert $ NEL .nubByEq nubPred (nel 1 [2 , 2 , 3 , 3 , 4 , 4 , 1 ]) == nel 1 [2 , 3 , 3 , 4 , 1 ]
198
+ let mod3eq = eq `on` \n -> mod n 3
199
+ assert $ NEL .nubByEq mod3eq (nel 1 [3 , 4 , 5 , 6 ]) == nel 1 [3 , 5 ]
191
200
192
201
log " union should produce the union of two lists"
193
202
assert $ NEL .union (nel 1 [2 , 3 ]) (nel 2 [3 , 4 ]) == nel 1 [2 , 3 , 4 ]
0 commit comments