@@ -5,7 +5,7 @@ import Data.List.NonEmpty as NEL
5
5
import Control.Monad.Eff (Eff )
6
6
import Control.Monad.Eff.Console (CONSOLE , log )
7
7
import 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 , (:))
9
9
import Data.Maybe (Maybe (..), isNothing , fromJust )
10
10
import Data.Monoid.Additive (Additive (..))
11
11
import Data.NonEmpty ((:|))
@@ -106,6 +106,17 @@ testList = do
106
106
assert $ unsafePartial (fromJust u2).head == 1
107
107
assert $ unsafePartial (fromJust u2).tail == l [2 , 3 ]
108
108
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
+
109
120
log " (!!) should return Just x when the index is within the bounds of the list"
110
121
assert $ l [1 , 2 , 3 ] !! 0 == (Just 1 )
111
122
assert $ l [1 , 2 , 3 ] !! 1 == (Just 2 )
0 commit comments