diff --git a/src/Data/Array.purs b/src/Data/Array.purs index 622c66cf..a510f0f3 100644 --- a/src/Data/Array.purs +++ b/src/Data/Array.purs @@ -32,8 +32,6 @@ module Data.Array , toUnfoldable , singleton , (..), range - , replicate - , replicateM , some , many @@ -141,15 +139,6 @@ foreign import range :: Int -> Int -> Array Int -- | An infix synonym for `range`. infix 8 range as .. --- | Create an array with repeated instances of a value. -foreign import replicate :: forall a. Int -> a -> Array a - --- | Perform a monadic action `n` times collecting all of the results. -replicateM :: forall m a. Monad m => Int -> m a -> m (Array a) -replicateM n m - | n < 1 = pure [] - | otherwise = sequence $ replicate n m - -- | Attempt a computation multiple times, requiring at least one success. -- | -- | The `Lazy` constraint is used to generate the result lazily, to ensure diff --git a/test/Test/Data/Array.purs b/test/Test/Data/Array.purs index cfc09da9..75085164 100644 --- a/test/Test/Data/Array.purs +++ b/test/Test/Data/Array.purs @@ -5,10 +5,11 @@ import Prelude import Control.Monad.Eff (Eff) import Control.Monad.Eff.Console (log, CONSOLE) -import Data.Array (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, (:), length, null, replicate, replicateM, singleton, fromFoldable) +import Data.Array (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, (:), length, null, singleton, fromFoldable) import Data.Foldable (for_, foldMapDefaultR, class Foldable, all) import Data.Maybe (Maybe(..), isNothing, fromJust) import Data.Tuple (Tuple(..)) +import Data.Unfoldable (replicate, replicateA) import Partial.Unsafe (unsafePartial) @@ -32,15 +33,15 @@ testArray = do assert $ replicate 0 "foo" == [] assert $ replicate (-1) "foo" == [] - log "replicateM should perform the monadic action the correct number of times" - assert $ replicateM 3 (Just 1) == Just [1, 1, 1] - assert $ replicateM 1 (Just 1) == Just [1] - assert $ replicateM 0 (Just 1) == Just [] - assert $ replicateM (-1) (Just 1) == Just [] + log "replicateA should perform the monadic action the correct number of times" + assert $ replicateA 3 (Just 1) == Just [1, 1, 1] + assert $ replicateA 1 (Just 1) == Just [1] + assert $ replicateA 0 (Just 1) == Just [] + assert $ replicateA (-1) (Just 1) == Just [] - log "replicateM should be stack safe" + log "replicateA should be stack safe" for_ [1, 1000, 2000, 20000, 50000] \n -> do - assert $ replicateM n (Just unit) == Just (replicate n unit) + assert $ replicateA n (Just unit) == Just (replicate n unit :: Array Unit) -- some -- many @@ -165,15 +166,15 @@ testArray = do assert $ (modifyAt 1 (_ + 1) nil) == Nothing log "alterAt should update an item at the specified index when the function returns Just" - assert $ (alterAt 0 (Just <<< (+ 1)) [1, 2, 3]) == Just [2, 2, 3] - assert $ (alterAt 1 (Just <<< (+ 1)) [1, 2, 3]) == Just [1, 3, 3] + assert $ (alterAt 0 (Just <<< (_ + 1)) [1, 2, 3]) == Just [2, 2, 3] + assert $ (alterAt 1 (Just <<< (_ + 1)) [1, 2, 3]) == Just [1, 3, 3] log "alterAt should drop an item at the specified index when the function returns Nothing" assert $ (alterAt 0 (const Nothing) [1, 2, 3]) == Just [2, 3] assert $ (alterAt 1 (const Nothing) [1, 2, 3]) == Just [1, 3] log "alterAt should return Nothing if the index is out of range" - assert $ (alterAt 1 (Just <<< (+ 1)) nil) == Nothing + assert $ (alterAt 1 (Just <<< (_ + 1)) nil) == Nothing log "reverse should reverse the order of items in an array" assert $ (reverse [1, 2, 3]) == [3, 2, 1]