@@ -5,7 +5,7 @@ import Data.List.NonEmpty as NEL
55import Control.Monad.Eff (Eff )
66import Control.Monad.Eff.Console (CONSOLE , log )
77import Data.Foldable (foldMap , foldl )
8- import Data.List (List (..), (..), length , range , 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 , filterM , filter , concat , concatMap , reverse , alterAt , modifyAt , updateAt , deleteAt , insertAt , findLastIndex , findIndex , elemLastIndex , elemIndex , (!!), uncons , init , tail , last , head , insertBy , insert , snoc , null , singleton , fromFoldable , transpose , mapWithIndex , (:))
8+ import Data.List (List (..), (..), length , range , 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 , 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 , (:))
99import Data.Maybe (Maybe (..), isNothing , fromJust )
1010import Data.Monoid.Additive (Additive (..))
1111import Data.NonEmpty ((:|))
@@ -106,6 +106,17 @@ testList = do
106106 assert $ unsafePartial (fromJust u2).head == 1
107107 assert $ unsafePartial (fromJust u2).tail == l [2 , 3 ]
108108
109+ log " unsnoc should return nothing when used on an empty list"
110+ assert $ isNothing (unsnoc nil)
111+
112+ log " unsnoc should split an list into an init and last record when there is at least one item"
113+ let v1 = unsnoc (l [1 ])
114+ assert $ unsafePartial (fromJust v1).init == l []
115+ assert $ unsafePartial (fromJust v1).last == 1
116+ let v2 = unsnoc (l [1 , 2 , 3 ])
117+ assert $ unsafePartial (fromJust v2).init == l [1 , 2 ]
118+ assert $ unsafePartial (fromJust v2).last == 3
119+
109120 log " (!!) should return Just x when the index is within the bounds of the list"
110121 assert $ l [1 , 2 , 3 ] !! 0 == (Just 1 )
111122 assert $ l [1 , 2 , 3 ] !! 1 == (Just 2 )
0 commit comments