Skip to content

Commit 000cacd

Browse files
committed
Remove redundant replicate
1 parent b31dfa8 commit 000cacd

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

src/Data/Array.purs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ module Data.Array
3232
, toUnfoldable
3333
, singleton
3434
, (..), range
35-
, replicate
36-
, replicateM
3735
, some
3836
, many
3937

@@ -141,15 +139,6 @@ foreign import range :: Int -> Int -> Array Int
141139
-- | An infix synonym for `range`.
142140
infix 8 range as ..
143141

144-
-- | Create an array with repeated instances of a value.
145-
foreign import replicate :: forall a. Int -> a -> Array a
146-
147-
-- | Perform a monadic action `n` times collecting all of the results.
148-
replicateM :: forall m a. Monad m => Int -> m a -> m (Array a)
149-
replicateM n m
150-
| n < 1 = pure []
151-
| otherwise = sequence $ replicate n m
152-
153142
-- | Attempt a computation multiple times, requiring at least one success.
154143
-- |
155144
-- | The `Lazy` constraint is used to generate the result lazily, to ensure

test/Test/Data/Array.purs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import Prelude
55
import Control.Monad.Eff (Eff)
66
import Control.Monad.Eff.Console (log, CONSOLE)
77

8-
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)
8+
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)
99
import Data.Foldable (for_, foldMapDefaultR, class Foldable, all)
1010
import Data.Maybe (Maybe(..), isNothing, fromJust)
1111
import Data.Tuple (Tuple(..))
12+
import Data.Unfoldable (replicate, replicateA)
1213

1314
import Partial.Unsafe (unsafePartial)
1415

@@ -32,15 +33,15 @@ testArray = do
3233
assert $ replicate 0 "foo" == []
3334
assert $ replicate (-1) "foo" == []
3435

35-
log "replicateM should perform the monadic action the correct number of times"
36-
assert $ replicateM 3 (Just 1) == Just [1, 1, 1]
37-
assert $ replicateM 1 (Just 1) == Just [1]
38-
assert $ replicateM 0 (Just 1) == Just []
39-
assert $ replicateM (-1) (Just 1) == Just []
36+
log "replicateA should perform the monadic action the correct number of times"
37+
assert $ replicateA 3 (Just 1) == Just [1, 1, 1]
38+
assert $ replicateA 1 (Just 1) == Just [1]
39+
assert $ replicateA 0 (Just 1) == Just []
40+
assert $ replicateA (-1) (Just 1) == Just []
4041

41-
log "replicateM should be stack safe"
42+
log "replicateA should be stack safe"
4243
for_ [1, 1000, 2000, 20000, 50000] \n -> do
43-
assert $ replicateM n (Just unit) == Just (replicate n unit)
44+
assert $ replicateA n (Just unit) == Just (replicate n unit :: Array Unit)
4445

4546
-- some
4647
-- many
@@ -165,15 +166,15 @@ testArray = do
165166
assert $ (modifyAt 1 (_ + 1) nil) == Nothing
166167

167168
log "alterAt should update an item at the specified index when the function returns Just"
168-
assert $ (alterAt 0 (Just <<< (+ 1)) [1, 2, 3]) == Just [2, 2, 3]
169-
assert $ (alterAt 1 (Just <<< (+ 1)) [1, 2, 3]) == Just [1, 3, 3]
169+
assert $ (alterAt 0 (Just <<< (_ + 1)) [1, 2, 3]) == Just [2, 2, 3]
170+
assert $ (alterAt 1 (Just <<< (_ + 1)) [1, 2, 3]) == Just [1, 3, 3]
170171

171172
log "alterAt should drop an item at the specified index when the function returns Nothing"
172173
assert $ (alterAt 0 (const Nothing) [1, 2, 3]) == Just [2, 3]
173174
assert $ (alterAt 1 (const Nothing) [1, 2, 3]) == Just [1, 3]
174175

175176
log "alterAt should return Nothing if the index is out of range"
176-
assert $ (alterAt 1 (Just <<< (+ 1)) nil) == Nothing
177+
assert $ (alterAt 1 (Just <<< (_ + 1)) nil) == Nothing
177178

178179
log "reverse should reverse the order of items in an array"
179180
assert $ (reverse [1, 2, 3]) == [3, 2, 1]

0 commit comments

Comments
 (0)