Skip to content

Commit ce0536f

Browse files
committed
Array replicate
1 parent ec16bf6 commit ce0536f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Data/Array.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ exports.range = function (start) {
1616
};
1717
};
1818

19+
exports.replicate = function (count) {
20+
return function (value) {
21+
var result = [];
22+
var n = 0;
23+
for (var i = 0; i < count; i++) {
24+
result[n++] = value;
25+
}
26+
return result;
27+
};
28+
};
29+
1930
exports.fromFoldableImpl = (function () {
2031
// jshint maxparams: 2
2132
function Cons(head, tail) {

src/Data/Array.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Data.Array
3232
, toUnfoldable
3333
, singleton
3434
, (..), range
35+
, replicate
3536
, some
3637
, many
3738

@@ -141,6 +142,9 @@ singleton a = [a]
141142
-- | Create an array containing a range of integers, including both endpoints.
142143
foreign import range :: Int -> Int -> Array Int
143144

145+
-- | Create an array containing a value repeated the specified number of times.
146+
foreign import replicate :: forall a. Int -> a -> Array a
147+
144148
-- | An infix synonym for `range`.
145149
infix 8 range as ..
146150

0 commit comments

Comments
 (0)