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]
431
431
Remove the longest initial subarray for which all element satisfy the specified predicate,
432
432
creating a new array.
433
433
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
+
434
442
#### ` functorArray `
435
443
436
444
``` purescript
@@ -662,4 +670,7 @@ init :: forall a. [a] -> [a]
662
670
663
671
Get all but the last element of a non-empty array.
664
672
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
51
51
, span
52
52
, dropWhile
53
53
, takeWhile
54
+ , replicate
54
55
) where
55
56
56
57
import Control.Alt
@@ -479,6 +480,21 @@ takeWhile p xs = (span p xs).init
479
480
dropWhile :: forall a . (a -> Boolean ) -> [a ] -> [a ]
480
481
dropWhile p xs = (span p xs).rest
481
482
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
+
482
498
instance functorArray :: Functor [] where
483
499
(<$>) = map
484
500
You can’t perform that action at this time.
0 commit comments