File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -431,6 +431,14 @@ dropWhile :: forall a. (a -> Boolean) -> [a] -> [a]
431431Remove the longest initial subarray for which all element satisfy the specified predicate,
432432creating a new array.
433433
434+ #### ` replicate `
435+
436+ ``` purescript
437+ replicate :: forall a. Number -> a -> [a]
438+ ```
439+
440+ Create an array with repeated instances of a value.
441+
434442#### ` functorArray `
435443
436444``` purescript
@@ -662,4 +670,7 @@ init :: forall a. [a] -> [a]
662670
663671Get all but the last element of a non-empty array.
664672
665- Running time: ` O(n) ` , where ` n ` is the length of the array.
673+ Running time: ` O(n) ` , where ` n ` is the length of the array.
674+
675+
676+
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ module Data.Array
5151 , span
5252 , dropWhile
5353 , takeWhile
54+ , replicate
5455 ) where
5556
5657import Control.Alt
@@ -479,6 +480,21 @@ takeWhile p xs = (span p xs).init
479480dropWhile :: forall a . (a -> Boolean ) -> [a ] -> [a ]
480481dropWhile p xs = (span p xs).rest
481482
483+
484+ -- | Create an array with repeated instances of a value.
485+ foreign import replicate
486+ """
487+ function replicate(nn) {
488+ return function(v) {
489+ var n = nn > 0? nn : 0;
490+ var r = new Array(n);
491+ for (var i = 0; i < n; i++)
492+ r[i] = v;
493+ return r;
494+ };
495+ }
496+ """ :: forall a . Number -> a -> [a ]
497+
482498instance functorArray :: Functor [] where
483499 (<$>) = map
484500
You can’t perform that action at this time.
0 commit comments