@@ -8,6 +8,8 @@ import Control.Monad.Eff.Console (log, CONSOLE)
8
8
import Data.Array (range , replicate , foldM , unzip , zip , zipWithA , zipWith , intersectBy , intersect , (\\), deleteBy , delete , unionBy , union , nubBy , nub , groupBy , group' , group , span , dropWhile , drop , takeWhile , take , sortBy , sort , catMaybes , mapMaybe , mapWithIndex , filterM , filter , concat , concatMap , reverse , alterAt , modifyAt , updateAt , deleteAt , insertAt , findLastIndex , findIndex , elemLastIndex , elemIndex , (!!), uncons , init , tail , last , head , insertBy , insert , snoc , (:), length , null , singleton , fromFoldable )
9
9
import Data.Foldable (for_ , foldMapDefaultR , class Foldable , all )
10
10
import Data.Maybe (Maybe (..), isNothing , fromJust )
11
+ import Data.NonEmpty ((:|))
12
+ import Data.NonEmpty as NE
11
13
import Data.Tuple (Tuple (..))
12
14
import Data.Unfoldable (replicateA )
13
15
@@ -240,13 +242,13 @@ testArray = do
240
242
assert $ spanResult.rest == [4 , 5 , 6 , 7 ]
241
243
242
244
log " group should group consecutive equal elements into arrays"
243
- assert $ group [1 , 2 , 2 , 3 , 3 , 3 , 1 ] == [[ 1 ], [ 2 , 2 ], [ 3 , 3 , 3 ], [ 1 ] ]
245
+ assert $ group [1 , 2 , 2 , 3 , 3 , 3 , 1 ] == [NE .singleton 1 , 2 :| [ 2 ], 3 :| [ 3 , 3 ], NE .singleton 1 ]
244
246
245
247
log " group' should sort then group consecutive equal elements into arrays"
246
- assert $ group' [1 , 2 , 2 , 3 , 3 , 3 , 1 ] == [[ 1 , 1 ], [ 2 , 2 ], [ 3 , 3 , 3 ]]
248
+ assert $ group' [1 , 2 , 2 , 3 , 3 , 3 , 1 ] == [1 :| [ 1 ], 2 :| [ 2 ], 3 :| [ 3 , 3 ]]
247
249
248
250
log " groupBy should group consecutive equal elements into arrays based on an equivalence relation"
249
- assert $ groupBy (\x y -> odd x && odd y) [1 , 1 , 2 , 2 , 3 , 3 ] == [[ 1 , 1 ], [ 2 ], [ 2 ], [ 3 , 3 ]]
251
+ assert $ groupBy (\x y -> odd x && odd y) [1 , 1 , 2 , 2 , 3 , 3 ] == [1 :| [ 1 ], NE .singleton 2 , NE .singleton 2 , 3 :| [ 3 ]]
250
252
251
253
log " nub should remove duplicate elements from the list, keeping the first occurence"
252
254
assert $ nub [1 , 2 , 2 , 3 , 4 , 1 ] == [1 , 2 , 3 , 4 ]
0 commit comments