@@ -3,19 +3,21 @@ module Test.Data.List.Lazy (testListLazy) where
33import Prelude
44
55import Control.Lazy (defer )
6- import Effect (Effect )
7- import Effect.Console (log )
86import Data.FoldableWithIndex (foldMapWithIndex , foldlWithIndex , foldrWithIndex )
97import Data.FunctorWithIndex (mapWithIndex )
108import Data.Lazy as Z
11- import Data.List.Lazy (List , nil , stripPrefix , Pattern (..), cons , foldl , foldr , foldMap , singleton , transpose , take , iterate , filter , uncons , foldM , foldrLazy , range , unzip , zip , length , zipWithA , replicate , repeat , zipWith , intersectBy , intersect , deleteBy , delete , unionBy , union , nubBy , nub , groupBy , group , partition , span , dropWhile , drop , takeWhile , slice , catMaybes , mapMaybe , filterM , concat , concatMap , reverse , alterAt , modifyAt , updateAt , deleteAt , insertAt , findLastIndex , findIndex , elemLastIndex , elemIndex , init , tail , last , head , insertBy , insert , snoc , null , replicateM , fromFoldable , (:), (\\), (!! ))
9+ import Data.List.Lazy (List , Pattern (..), alterAt , catMaybes , concat , concatMap , cons , delete , deleteAt , deleteBy , drop , dropWhile , elemIndex , elemLastIndex , filter , filterM , findIndex , findLastIndex , foldM , foldMap , foldl , foldr , foldrLazy , fromFoldable , group , groupBy , head , init , insert , insertAt , insertBy , intersect , intersectBy , iterate , last , length , mapMaybe , modifyAt , nil , nub , nubBy , null , partition , range , repeat , replicate , replicateM , reverse , singleton , slice , snoc , span , stripPrefix , tail , take , takeWhile , transpose , uncons , union , unionBy , unzip , updateAt , zip , zipWith , zipWithA , (!!), (..) , (:), (\\))
1210import Data.List.Lazy.NonEmpty as NEL
1311import Data.Maybe (Maybe (..), isNothing , fromJust )
1412import Data.Monoid.Additive (Additive (..))
1513import Data.NonEmpty ((:|))
1614import Data.Traversable (traverse )
1715import Data.TraversableWithIndex (traverseWithIndex )
1816import Data.Tuple (Tuple (..))
17+ import Data.Unfoldable (unfoldr )
18+ import Data.Unfoldable1 (unfoldr1 )
19+ import Effect (Effect )
20+ import Effect.Console (log )
1921import Partial.Unsafe (unsafePartial )
2022import Test.Assert (assert )
2123
@@ -396,9 +398,26 @@ testListLazy = do
396398 ((10 :20 :30 :nil) : (11 :31 :nil) : (32 :nil) : nil)
397399 log " transpose nil == nil"
398400 assert $ transpose nil == (nil :: List (List Int ))
401+
399402 log " transpose (singleton nil) == nil"
400403 assert $ transpose (singleton nil) == (nil :: List (List Int ))
401404
405+ log " unfoldr should maintain order"
406+ assert $ (1 ..5 ) == unfoldr step 1
407+
408+ log " unfoldr1 should maintain order"
409+ assert $ (1 ..5 ) == unfoldr1 step1 1
410+
411+ log " map should maintain order"
412+ assert $ (1 ..5 ) == map identity (1 ..5 )
413+
414+ step :: Int -> Maybe (Tuple Int Int )
415+ step 6 = Nothing
416+ step n = Just (Tuple n (n + 1 ))
417+
418+ step1 :: Int -> Tuple Int (Maybe Int )
419+ step1 n = Tuple n (if n >= 5 then Nothing else Just (n + 1 ))
420+
402421nil' :: List Int
403422nil' = nil
404423
0 commit comments