Skip to content

Commit dfede46

Browse files
committed
Updates for 0.7
1 parent 2a4f63d commit dfede46

File tree

8 files changed

+15
-90
lines changed

8 files changed

+15
-90
lines changed

src/Data/Array.js

-26
Original file line numberDiff line numberDiff line change
@@ -211,29 +211,3 @@ exports.zipWith = function (f) {
211211
};
212212
};
213213
};
214-
215-
//------------------------------------------------------------------------------
216-
// Folding ---------------------------------------------------------------------
217-
//------------------------------------------------------------------------------
218-
219-
exports.foldrArray = function (f) {
220-
return function (init) {
221-
return function (xs) {
222-
/* jshint maxparams: 2 */
223-
return xs.reduceRight(function (acc, x) {
224-
return f(x)(acc);
225-
}, init);
226-
};
227-
};
228-
};
229-
230-
exports.foldlArray = function (f) {
231-
return function (init) {
232-
return function (xs) {
233-
/* jshint maxparams: 2 */
234-
return xs.reduce(function (acc, x) {
235-
return f(acc)(x);
236-
}, init);
237-
};
238-
};
239-
};

src/Data/Array.purs

+2-63
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ module Data.Array
99
( singleton
1010
, (..), range
1111
, replicate
12-
, replicateM
13-
, some
14-
, many
1512

1613
, null
1714
, length
@@ -39,7 +36,6 @@ module Data.Array
3936
, concat
4037
, concatMap
4138
, filter
42-
, filterM
4339
, mapMaybe
4440
, catMaybes
4541

@@ -69,10 +65,10 @@ module Data.Array
6965
, zipWithA
7066
, zip
7167
, unzip
72-
73-
, foldM
7468
) where
7569

70+
import Prelude
71+
7672
import Control.Alt (Alt, (<|>))
7773
import Control.Alternative (Alternative)
7874
import Control.Lazy (Lazy, defer)
@@ -105,28 +101,6 @@ infix 8 ..
105101
-- | Create an array with repeated instances of a value.
106102
foreign import replicate :: forall a. Int -> a -> Array a
107103

108-
-- | Perform a monadic action `n` times collecting all of the results.
109-
replicateM :: forall m a. (Monad m) => Int -> m a -> m (Array a)
110-
replicateM n m | n < 1 = return []
111-
| otherwise = do a <- m
112-
as <- replicateM (n - 1) m
113-
return (a : as)
114-
115-
-- | Attempt a computation multiple times, requiring at least one success.
116-
-- |
117-
-- | The `Lazy` constraint is used to generate the result lazily, to ensure
118-
-- | termination.
119-
some :: forall f a. (Alternative f, Lazy (f (Array a))) => f a -> f (Array a)
120-
some v = (:) <$> v <*> defer (\_ -> many v)
121-
122-
-- | Attempt a computation multiple times, returning as many successful results
123-
-- | as possible (possibly zero).
124-
-- |
125-
-- | The `Lazy` constraint is used to generate the result lazily, to ensure
126-
-- | termination.
127-
many :: forall f a. (Alternative f, Lazy (f (Array a))) => f a -> f (Array a)
128-
many v = some v <|> pure []
129-
130104
--------------------------------------------------------------------------------
131105
-- Array size ------------------------------------------------------------------
132106
--------------------------------------------------------------------------------
@@ -281,20 +255,6 @@ concatMap = flip bind
281255
-- | creating a new array.
282256
foreign import filter :: forall a. (a -> Boolean) -> Array a -> Array a
283257

284-
-- | Filter where the predicate returns a monadic `Boolean`.
285-
-- |
286-
-- | ```purescript
287-
-- | powerSet :: forall a. [a] -> [[a]]
288-
-- | powerSet = filterM (const [true, false])
289-
-- | ```
290-
filterM :: forall a m. (Monad m) => (a -> m Boolean) -> Array a -> m (Array a)
291-
filterM p = uncons' (\_ -> pure []) \x xs -> do
292-
b <- p x
293-
xs' <- filterM p xs
294-
return if b
295-
then x : xs'
296-
else xs'
297-
298258
-- | Apply a function to each element in an array, keeping only the results
299259
-- | which contain a value, creating a new array.
300260
mapMaybe :: forall a b. (a -> Maybe b) -> Array a -> Array b
@@ -470,18 +430,6 @@ unzip :: forall a b. Array (Tuple a b) -> Tuple (Array a) (Array b)
470430
unzip = uncons' (\_ -> Tuple [] []) \(Tuple a b) ts -> case unzip ts of
471431
Tuple as bs -> Tuple (a : as) (b : bs)
472432

473-
--------------------------------------------------------------------------------
474-
-- Folding ---------------------------------------------------------------------
475-
--------------------------------------------------------------------------------
476-
477-
-- | Perform a fold using a monadic step function.
478-
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> Array b -> m a
479-
foldM f a = uncons' (\_ -> return a) (\b bs -> f a b >>= \a' -> foldM f a' bs)
480-
481-
foreign import foldrArray :: forall a b. (a -> b -> b) -> b -> Array a -> b
482-
483-
foreign import foldlArray :: forall a b. (b -> a -> b) -> b -> Array a -> b
484-
485433
--------------------------------------------------------------------------------
486434
-- Non-Prelude instances -------------------------------------------------------
487435
--------------------------------------------------------------------------------
@@ -496,14 +444,5 @@ instance alternativeArray :: Alternative Array
496444

497445
instance monadPlusArray :: MonadPlus Array
498446

499-
instance foldableArray :: Foldable Array where
500-
foldr f z xs = foldrArray f z xs
501-
foldl f z xs = foldlArray f z xs
502-
foldMap f xs = foldr (\x acc -> f x <> acc) mempty xs
503-
504-
instance traversableArray :: Traversable Array where
505-
traverse f = uncons' (\_ -> pure []) (\x xs -> (:) <$> (f x) <*> traverse f xs)
506-
sequence = uncons' (\_ -> pure []) (\x xs -> (:) <$> x <*> sequence xs)
507-
508447
instance invariantArray :: Invariant Array where
509448
imap = imapF

src/Data/Array/ST.purs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module Data.Array.ST
1616
, toAssocArray
1717
) where
1818

19+
import Prelude
20+
1921
import Control.Monad.Eff (Eff())
2022
import Control.Monad.ST (ST())
2123
import Data.Maybe (Maybe(..))
@@ -25,7 +27,7 @@ import Data.Maybe (Maybe(..))
2527
-- | The first type parameter represents the memory region which the array belongs to.
2628
-- | The second type parameter defines the type of elements of the mutable array.
2729
-- |
28-
-- | The runtime representation of a value of type `STArray h a` is the same as that of `[a]`,
30+
-- | The runtime representation of a value of type `STArray h a` is the same as that of `Array a`,
2931
-- | except that mutation is allowed.
3032
foreign import data STArray :: * -> * -> *
3133

src/Data/Array/Unsafe.purs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
module Data.Array.Unsafe where
77

8+
import Prelude
9+
810
import Data.Array (length, slice)
911

1012
-- | Find the element of an array at the specified index.

test/Test/Data/Array.purs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module Test.Data.Array (testArray) where
22

3+
import Prelude
4+
35
import Console (log)
46
import Data.Array
57
import Data.Maybe (Maybe(..), isNothing)

test/Test/Data/Array/ST.purs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module Test.Data.Array.ST (testArrayST) where
22

3+
import Prelude
4+
35
import Console (log, print)
46
import Control.Monad.Eff (runPure)
57
import Control.Monad.ST (runST)

test/Test/Data/Array/Unsafe.purs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module Test.Data.Array.Unsafe (testArrayUnsafe) where
22

3+
import Prelude
4+
35
import Console (log)
46
import Data.Array.Unsafe
57
import Test.Assert (assert)

test/Test/Main.purs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module Test.Main where
22

3+
import Prelude
4+
35
import Test.Data.Array
46
import Test.Data.Array.ST
57
import Test.Data.Array.Unsafe

0 commit comments

Comments
 (0)