Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ dropWhile :: forall a. (a -> Boolean) -> [a] -> [a]
Remove the longest initial subarray for which all element satisfy the specified predicate,
creating a new array.

#### `replicate`

``` purescript
replicate :: forall a. Number -> a -> [a]
```

Create an array with repeated instances of a value.

#### `functorArray`

``` purescript
Expand Down Expand Up @@ -662,4 +670,7 @@ init :: forall a. [a] -> [a]

Get all but the last element of a non-empty array.

Running time: `O(n)`, where `n` is the length of the array.
Running time: `O(n)`, where `n` is the length of the array.



16 changes: 16 additions & 0 deletions src/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module Data.Array
, span
, dropWhile
, takeWhile
, replicate
) where

import Control.Alt
Expand Down Expand Up @@ -479,6 +480,21 @@ takeWhile p xs = (span p xs).init
dropWhile :: forall a. (a -> Boolean) -> [a] -> [a]
dropWhile p xs = (span p xs).rest


-- | Create an array with repeated instances of a value.
foreign import replicate
"""
function replicate(nn) {
return function(v) {
var n = nn > 0? nn : 0;
var r = new Array(n);
for (var i = 0; i < n; i++)
r[i] = v;
return r;
};
}
""" :: forall a. Number -> a -> [a]

instance functorArray :: Functor [] where
(<$>) = map

Expand Down