Skip to content

Commit

Permalink
Merge pull request #73 from purescript/bump
Browse files Browse the repository at this point in the history
Prepare for 2.0 release
  • Loading branch information
garyb authored Oct 7, 2016
2 parents 90b1c3d + 19ff68f commit a8e463b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 40 deletions.
13 changes: 7 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
"package.json"
],
"dependencies": {
"purescript-foldable-traversable": "^1.0.0",
"purescript-foldable-traversable": "^2.0.0",
"purescript-partial": "^1.1.0",
"purescript-st": "^1.0.0",
"purescript-tuples": "^1.0.0",
"purescript-unfoldable": "^1.0.0"
"purescript-st": "^2.0.0",
"purescript-tailrec": "^2.0.0",
"purescript-tuples": "^3.0.0",
"purescript-unfoldable": "^2.0.0"
},
"devDependencies": {
"purescript-assert": "^1.0.0",
"purescript-console": "^1.0.0"
"purescript-assert": "^2.0.0",
"purescript-console": "^2.0.0"
}
}
24 changes: 21 additions & 3 deletions src/Data/Array.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* global exports */
"use strict";

// module Data.Array

//------------------------------------------------------------------------------
// Array creation --------------------------------------------------------------
//------------------------------------------------------------------------------
Expand All @@ -19,6 +16,17 @@ exports.range = function (start) {
};
};

exports.replicate = function (count) {
return function (value) {
var result = [];
var n = 0;
for (var i = 0; i < count; i++) {
result[n++] = value;
}
return result;
};
};

exports.fromFoldableImpl = (function () {
// jshint maxparams: 2
function Cons(head, tail) {
Expand Down Expand Up @@ -264,3 +272,13 @@ exports.zipWith = function (f) {
};
};
};

//------------------------------------------------------------------------------
// Partial ---------------------------------------------------------------------
//------------------------------------------------------------------------------

exports.unsafeIndexImpl = function (xs) {
return function (n) {
return xs[n];
};
};
44 changes: 37 additions & 7 deletions src/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Data.Array
, toUnfoldable
, singleton
, (..), range
, replicate
, some
, many

Expand Down Expand Up @@ -100,16 +101,24 @@ module Data.Array
, unzip

, foldM
, foldRecM

, unsafeIndex

, module Exports
) where

import Prelude

import Control.Alt ((<|>))
import Control.Alternative (class Alternative)
import Control.Lazy (class Lazy, defer)
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM2)

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

-- | Create an array containing a value repeated the specified number of times.
foreign import replicate :: forall a. Int -> a -> Array a

-- | An infix synonym for `range`.
infix 8 range as ..

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

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

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

-- | Sort the elements of an array in increasing order, where elements are compared using
-- | the specified partial ordering, creating a new array.
-- | Sort the elements of an array in increasing order, where elements are
-- | compared using the specified partial ordering, creating a new array.
sortBy :: forall a. (a -> a -> Ordering) -> Array a -> Array a
sortBy comp xs = sortImpl comp' xs
where
Expand Down Expand Up @@ -590,8 +604,8 @@ foreign import zipWith
-> Array b
-> Array c

-- | A generalization of `zipWith` which accumulates results in some `Applicative`
-- | functor.
-- | A generalization of `zipWith` which accumulates results in some
-- | `Applicative` functor.
zipWithA
:: forall m a b c
. Applicative m
Expand All @@ -602,7 +616,8 @@ zipWithA
zipWithA f xs ys = sequence (zipWith f xs ys)

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

Expand All @@ -615,3 +630,18 @@ unzip = uncons' (\_ -> Tuple [] []) \(Tuple a b) ts -> case unzip ts of
-- | Perform a fold using a monadic step function.
foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> Array b -> m a
foldM f a = uncons' (\_ -> pure a) (\b bs -> f a b >>= \a' -> foldM f a' bs)

foldRecM :: forall m a b. MonadRec m => (a -> b -> m a) -> a -> Array b -> m a
foldRecM f a array = tailRecM2 go a 0
where
go res i
| i >= length array = pure (Done res)
| otherwise = do
res' <- f res (unsafePartial (unsafeIndex array i))
pure (Loop { a: res', b: i + 1 })

-- | Find the element of an array at the specified index.
unsafeIndex :: forall a. Partial => Array a -> Int -> a
unsafeIndex = unsafeIndexImpl

foreign import unsafeIndexImpl :: forall a. Array a -> Int -> a
10 changes: 0 additions & 10 deletions src/Data/Array/Partial.js

This file was deleted.

11 changes: 2 additions & 9 deletions src/Data/Array/Partial.purs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
-- | Partial helper functions for working with immutable arrays.
module Data.Array.Partial
( unsafeIndex
, head
( head
, tail
, last
, init
) where

import Prelude

import Data.Array (length, slice)

-- | Find the element of an array at the specified index.
unsafeIndex :: forall a. Partial => Array a -> Int -> a
unsafeIndex = unsafeIndexImpl

foreign import unsafeIndexImpl :: forall a. Array a -> Int -> a
import Data.Array (length, slice, unsafeIndex)

-- | Get the first element of a non-empty array.
-- |
Expand Down
3 changes: 0 additions & 3 deletions src/Data/Array/ST.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* global exports */
"use strict";

// module Data.Array.ST

exports.runSTArray = function (f) {
return f;
};
Expand Down
4 changes: 2 additions & 2 deletions test/Test/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (log, CONSOLE)

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)
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)
import Data.Foldable (for_, foldMapDefaultR, class Foldable, all)
import Data.Maybe (Maybe(..), isNothing, fromJust)
import Data.Tuple (Tuple(..))
import Data.Unfoldable (replicate, replicateA)
import Data.Unfoldable (replicateA)

import Partial.Unsafe (unsafePartial)

Expand Down

0 comments on commit a8e463b

Please sign in to comment.