Skip to content

Commit a8e463b

Browse files
authored
Merge pull request #73 from purescript/bump
Prepare for 2.0 release
2 parents 90b1c3d + 19ff68f commit a8e463b

File tree

7 files changed

+69
-40
lines changed

7 files changed

+69
-40
lines changed

bower.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-foldable-traversable": "^1.0.0",
19+
"purescript-foldable-traversable": "^2.0.0",
2020
"purescript-partial": "^1.1.0",
21-
"purescript-st": "^1.0.0",
22-
"purescript-tuples": "^1.0.0",
23-
"purescript-unfoldable": "^1.0.0"
21+
"purescript-st": "^2.0.0",
22+
"purescript-tailrec": "^2.0.0",
23+
"purescript-tuples": "^3.0.0",
24+
"purescript-unfoldable": "^2.0.0"
2425
},
2526
"devDependencies": {
26-
"purescript-assert": "^1.0.0",
27-
"purescript-console": "^1.0.0"
27+
"purescript-assert": "^2.0.0",
28+
"purescript-console": "^2.0.0"
2829
}
2930
}

src/Data/Array.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
/* global exports */
21
"use strict";
32

4-
// module Data.Array
5-
63
//------------------------------------------------------------------------------
74
// Array creation --------------------------------------------------------------
85
//------------------------------------------------------------------------------
@@ -19,6 +16,17 @@ exports.range = function (start) {
1916
};
2017
};
2118

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+
2230
exports.fromFoldableImpl = (function () {
2331
// jshint maxparams: 2
2432
function Cons(head, tail) {
@@ -264,3 +272,13 @@ exports.zipWith = function (f) {
264272
};
265273
};
266274
};
275+
276+
//------------------------------------------------------------------------------
277+
// Partial ---------------------------------------------------------------------
278+
//------------------------------------------------------------------------------
279+
280+
exports.unsafeIndexImpl = function (xs) {
281+
return function (n) {
282+
return xs[n];
283+
};
284+
};

src/Data/Array.purs

Lines changed: 37 additions & 7 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

@@ -100,16 +101,24 @@ module Data.Array
100101
, unzip
101102

102103
, foldM
104+
, foldRecM
105+
106+
, unsafeIndex
107+
108+
, module Exports
103109
) where
104110

105111
import Prelude
106112

107113
import Control.Alt ((<|>))
108114
import Control.Alternative (class Alternative)
109115
import Control.Lazy (class Lazy, defer)
116+
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM2)
110117

111118
import Data.Foldable (class Foldable, foldl, foldr)
119+
import Data.Foldable (foldl, foldr, foldMap, fold, intercalate, elem, notElem, find, findMap, any, all) as Exports
112120
import Data.Maybe (Maybe(..), maybe, isJust, fromJust)
121+
import Data.Traversable (scanl, scanr) as Exports
113122
import Data.Traversable (sequence)
114123
import Data.Tuple (Tuple(..))
115124
import Data.Unfoldable (class Unfoldable, unfoldr)
@@ -137,6 +146,9 @@ singleton a = [a]
137146
-- | Create an array containing a range of integers, including both endpoints.
138147
foreign import range :: Int -> Int -> Array Int
139148

149+
-- | Create an array containing a value repeated the specified number of times.
150+
foreign import replicate :: forall a. Int -> a -> Array a
151+
140152
-- | An infix synonym for `range`.
141153
infix 8 range as ..
142154

@@ -214,13 +226,15 @@ head = uncons' (const Nothing) (\x _ -> Just x)
214226
last :: forall a. Array a -> Maybe a
215227
last xs = xs !! (length xs - 1)
216228

217-
-- | Get all but the first element of an array, creating a new array, or `Nothing` if the array is empty
229+
-- | Get all but the first element of an array, creating a new array, or
230+
-- | `Nothing` if the array is empty
218231
-- |
219232
-- | Running time: `O(n)` where `n` is the length of the array
220233
tail :: forall a. Array a -> Maybe (Array a)
221234
tail = uncons' (const Nothing) (\_ xs -> Just xs)
222235

223-
-- | Get all but the last element of an array, creating a new array, or `Nothing` if the array is empty.
236+
-- | Get all but the last element of an array, creating a new array, or
237+
-- | `Nothing` if the array is empty.
224238
-- |
225239
-- | Running time: `O(n)` where `n` is the length of the array
226240
init :: forall a. Array a -> Maybe (Array a)
@@ -428,8 +442,8 @@ mapWithIndex f xs =
428442
sort :: forall a. Ord a => Array a -> Array a
429443
sort xs = sortBy compare xs
430444

431-
-- | Sort the elements of an array in increasing order, where elements are compared using
432-
-- | the specified partial ordering, creating a new array.
445+
-- | Sort the elements of an array in increasing order, where elements are
446+
-- | compared using the specified partial ordering, creating a new array.
433447
sortBy :: forall a. (a -> a -> Ordering) -> Array a -> Array a
434448
sortBy comp xs = sortImpl comp' xs
435449
where
@@ -590,8 +604,8 @@ foreign import zipWith
590604
-> Array b
591605
-> Array c
592606

593-
-- | A generalization of `zipWith` which accumulates results in some `Applicative`
594-
-- | functor.
607+
-- | A generalization of `zipWith` which accumulates results in some
608+
-- | `Applicative` functor.
595609
zipWithA
596610
:: forall m a b c
597611
. Applicative m
@@ -602,7 +616,8 @@ zipWithA
602616
zipWithA f xs ys = sequence (zipWith f xs ys)
603617

604618
-- | Rakes two lists and returns a list of corresponding pairs.
605-
-- | If one input list is short, excess elements of the longer list are discarded.
619+
-- | If one input list is short, excess elements of the longer list are
620+
-- | discarded.
606621
zip :: forall a b. Array a -> Array b -> Array (Tuple a b)
607622
zip = zipWith Tuple
608623

@@ -615,3 +630,18 @@ unzip = uncons' (\_ -> Tuple [] []) \(Tuple a b) ts -> case unzip ts of
615630
-- | Perform a fold using a monadic step function.
616631
foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> Array b -> m a
617632
foldM f a = uncons' (\_ -> pure a) (\b bs -> f a b >>= \a' -> foldM f a' bs)
633+
634+
foldRecM :: forall m a b. MonadRec m => (a -> b -> m a) -> a -> Array b -> m a
635+
foldRecM f a array = tailRecM2 go a 0
636+
where
637+
go res i
638+
| i >= length array = pure (Done res)
639+
| otherwise = do
640+
res' <- f res (unsafePartial (unsafeIndex array i))
641+
pure (Loop { a: res', b: i + 1 })
642+
643+
-- | Find the element of an array at the specified index.
644+
unsafeIndex :: forall a. Partial => Array a -> Int -> a
645+
unsafeIndex = unsafeIndexImpl
646+
647+
foreign import unsafeIndexImpl :: forall a. Array a -> Int -> a

src/Data/Array/Partial.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Data/Array/Partial.purs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
-- | Partial helper functions for working with immutable arrays.
22
module Data.Array.Partial
3-
( unsafeIndex
4-
, head
3+
( head
54
, tail
65
, last
76
, init
87
) where
98

109
import Prelude
1110

12-
import Data.Array (length, slice)
13-
14-
-- | Find the element of an array at the specified index.
15-
unsafeIndex :: forall a. Partial => Array a -> Int -> a
16-
unsafeIndex = unsafeIndexImpl
17-
18-
foreign import unsafeIndexImpl :: forall a. Array a -> Int -> a
11+
import Data.Array (length, slice, unsafeIndex)
1912

2013
-- | Get the first element of a non-empty array.
2114
-- |

src/Data/Array/ST.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
/* global exports */
21
"use strict";
32

4-
// module Data.Array.ST
5-
63
exports.runSTArray = function (f) {
74
return f;
85
};

test/Test/Data/Array.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +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, mapWithIndex, 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)
8+
import Data.Array (range, replicate, 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, mapWithIndex, 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)
12+
import Data.Unfoldable (replicateA)
1313

1414
import Partial.Unsafe (unsafePartial)
1515

0 commit comments

Comments
 (0)