diff --git a/.travis.yml b/.travis.yml index 791313a..554955a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js sudo: false node_js: - - 0.10 + - 4 env: - PATH=$HOME/purescript:$PATH install: diff --git a/src/Data/List.purs b/src/Data/List.purs index 613cec7..3ef5711 100644 --- a/src/Data/List.purs +++ b/src/Data/List.purs @@ -71,7 +71,7 @@ module Data.List , unionBy , delete , deleteBy - , (\\) + , (\\), difference , intersect , intersectBy @@ -88,20 +88,20 @@ module Data.List , fromList ) where -import Prelude +import Prelude (class Monad, class Bind, class Applicative, class Apply, class Functor, class Semigroup, class Ord, class Eq, class Show, Ordering(EQ, GT, LT), append, flip, (<*>), (<$>), (<>), pure, (<<<), ($), compare, (==), (&&), show, (++), (>>=), return, not, eq, (-), otherwise, (/=), id, bind, (+), one, (<), (<=), negate, (>)) -import Control.Alt (Alt, (<|>)) -import Control.Alternative (Alternative) -import Control.Lazy (Lazy, defer) -import Control.MonadPlus (MonadPlus) -import Control.Plus (Plus) +import Control.Alt (class Alt, (<|>)) +import Control.Alternative (class Alternative) +import Control.Lazy (class Lazy, defer) +import Control.MonadPlus (class MonadPlus) +import Control.Plus (class Plus) -import Data.Foldable (Foldable, foldl, foldr, any) +import Data.Foldable (class Foldable, foldl, foldr, any) import Data.Maybe (Maybe(..)) -import Data.Monoid (Monoid, mempty) -import Data.Traversable (Traversable, traverse, sequence) +import Data.Monoid (class Monoid, mempty) +import Data.Traversable (class Traversable, traverse, sequence) import Data.Tuple (Tuple(..)) -import Data.Unfoldable (Unfoldable, unfoldr) +import Data.Unfoldable (class Unfoldable, unfoldr) -- | A strict linked list. -- | @@ -132,11 +132,8 @@ fromFoldable = foldr Cons Nil singleton :: forall a. a -> List a singleton a = Cons a Nil -infix 8 .. - -- | An infix synonym for `range`. -(..) :: Int -> Int -> List Int -(..) = range +infix 8 range as .. -- | Create a list containing a range of integers, including both endpoints. range :: Int -> Int -> List Int @@ -196,14 +193,11 @@ length = foldl (\acc _ -> acc + 1) 0 -- Extending arrays ------------------------------------------------------------ -------------------------------------------------------------------------------- -infixr 6 : - -- | An infix alias for `Cons`; attaches an element to the front of -- | a list. -- | -- | Running time: `O(1)` -(:) :: forall a. a -> List a -> List a -(:) = Cons +infixr 6 Cons as : -- | Append an element to the end of an array, creating a new array. -- | @@ -285,19 +279,16 @@ index Nil _ = Nothing index (Cons a _) 0 = Just a index (Cons _ as) i = index as (i - 1) -infixl 8 !! - -- | An infix synonym for `index`. -(!!) :: forall a. List a -> Int -> Maybe a -(!!) = index +infixl 8 index as !! -- | Find the index of the first element equal to the specified element. elemIndex :: forall a. (Eq a) => a -> List a -> Maybe Int -elemIndex x = findIndex (== x) +elemIndex x = findIndex (_ == x) -- | Find the index of the last element equal to the specified element. elemLastIndex :: forall a. (Eq a) => a -> List a -> Maybe Int -elemLastIndex x = findLastIndex (== x) +elemLastIndex x = findLastIndex (_ == x) -- | Find the first index for which a predicate holds. findIndex :: forall a. (a -> Boolean) -> List a -> Maybe Int @@ -377,7 +368,7 @@ reverse = go Nil -- | -- | Running time: `O(n)`, where `n` is the total number of elements. concat :: forall a. List (List a) -> List a -concat = (>>= id) +concat = (_ >>= id) -- | Apply a function to each element in a list, and flatten the results -- | into a single, new list. @@ -614,13 +605,13 @@ deleteBy _ _ Nil = Nil deleteBy (==) x (Cons y ys) | x == y = ys deleteBy (==) x (Cons y ys) = Cons y (deleteBy (==) x ys) -infix 5 \\ +infix 5 difference as \\ -- | Delete the first occurrence of each element in the second list from the first list. -- | -- | Running time: `O(n^2)` -(\\) :: forall a. (Eq a) => List a -> List a -> List a -(\\) = foldl (flip delete) +difference :: forall a. (Eq a) => List a -> List a -> List a +difference = foldl (flip delete) -- | Calculate the intersection of two lists. -- | diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index 6fbc1b6..4b84d73 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -78,7 +78,7 @@ module Data.List.Lazy , unionBy , delete , deleteBy - , (\\) + , (\\), difference , intersect , intersectBy @@ -94,21 +94,21 @@ module Data.List.Lazy , fromList ) where -import Prelude +import Prelude (class Monad, class Bind, class Applicative, class Apply, class Functor, class Semigroup, class Ord, class Eq, class Show, Ordering(EQ, GT, LT), append, flip, ap, (<*>), (<$>), pure, (<>), (<<<), ($), compare, (==), (++), show, otherwise, not, eq, (-), id, (>>=), (+), negate, (>)) -import Control.Alt (Alt) -import Control.Alternative (Alternative) -import Control.MonadPlus (MonadPlus) -import Control.Plus (Plus) -import qualified Control.Lazy as Z +import Control.Alt (class Alt) +import Control.Alternative (class Alternative) +import Control.MonadPlus (class MonadPlus) +import Control.Plus (class Plus) +import Control.Lazy as Z -import Data.Foldable (Foldable, foldMap, foldl, foldr, any) +import Data.Foldable (class Foldable, foldMap, foldl, foldr, any) import Data.Lazy (Lazy(), defer, force) import Data.Maybe (Maybe(..), isNothing) -import Data.Monoid (Monoid, mempty) -import Data.Traversable (Traversable, traverse, sequence) +import Data.Monoid (class Monoid, mempty) +import Data.Traversable (class Traversable, traverse, sequence) import Data.Tuple (Tuple(..)) -import Data.Unfoldable (Unfoldable, unfoldr) +import Data.Unfoldable (class Unfoldable, unfoldr) -- | A lazy linked list. @@ -159,8 +159,7 @@ singleton :: forall a. a -> List a singleton a = cons a nil -- | An infix synonym for `range`. -(..) :: Int -> Int -> List Int -(..) = range +infix 8 range as .. -- | Create a list containing a range of integers, including both endpoints. range :: Int -> Int -> List Int @@ -211,14 +210,11 @@ length xs = go (step xs) cons :: forall a. a -> List a -> List a cons x xs = List $ defer \_ -> Cons x xs -infixr 6 : - -- | An infix alias for `cons`; attaches an element to the front of -- | a list. -- | -- | Running time: `O(1)` -(:) :: forall a. a -> List a -> List a -(:) = cons +infixr 6 cons as : -- | Insert an element into a sorted list. -- | @@ -299,11 +295,8 @@ index xs = go (step xs) go (Cons a _) 0 = Just a go (Cons _ as) i = go (step as) (i - 1) -infixl 8 !! - -- | An infix synonym for `index`. -(!!) :: forall a. List a -> Int -> Maybe a -(!!) = index +infixl 8 index as !! -- | Insert an element into a list at the specified index, returning a new -- | list or `Nothing` if the index is out-of-bounds. @@ -392,7 +385,7 @@ reverse xs = go nil (step xs) -- | -- | Running time: `O(n)`, where `n` is the total number of elements. concat :: forall a. List (List a) -> List a -concat = (>>= id) +concat = (_ >>= id) -- | Apply a function to each element in a list, and flatten the results -- | into a single, new list. @@ -574,13 +567,12 @@ deleteBy eq x xs = List (go <$> runList xs) go (Cons y ys) | eq x y = step ys | otherwise = Cons y (deleteBy eq x ys) -infix 5 \\ - -- | Delete the first occurrence of each element in the second list from the first list. -- | -- | Running time: `O(n^2)` -(\\) :: forall a. (Eq a) => List a -> List a -> List a -(\\) = foldl (flip delete) +difference :: forall a. (Eq a) => List a -> List a -> List a +difference = foldl (flip delete) +infix 5 difference as \\ -- | Calculate the intersection of two lists. -- | diff --git a/src/Data/List/Unsafe.purs b/src/Data/List/Unsafe.purs index 27073e9..533127c 100644 --- a/src/Data/List/Unsafe.purs +++ b/src/Data/List/Unsafe.purs @@ -10,7 +10,6 @@ module Data.List.Unsafe , init ) where -import Prelude import Data.List (List(..)) -- | Get the first element of a non-empty list. diff --git a/src/Data/List/ZipList.purs b/src/Data/List/ZipList.purs index 6887e43..f8a44d4 100644 --- a/src/Data/List/ZipList.purs +++ b/src/Data/List/ZipList.purs @@ -6,16 +6,16 @@ module Data.List.ZipList , runZipList ) where -import Prelude +import Prelude (class Applicative, class Apply, class Functor, class Semigroup, class Ord, class Eq, class Show, append, (<<<), ($), map, (<$>), (++), compare, eq, show) -import Control.Alt (Alt) -import Control.Alternative (Alternative) -import Control.Plus (Plus) +import Control.Alt (class Alt) +import Control.Alternative (class Alternative) +import Control.Plus (class Plus) -import Data.Foldable (Foldable, foldMap, foldl, foldr) +import Data.Foldable (class Foldable, foldMap, foldl, foldr) import Data.List.Lazy (List(), repeat, zipWith) -import Data.Monoid (Monoid, mempty) -import Data.Traversable (Traversable, traverse, sequence) +import Data.Monoid (class Monoid, mempty) +import Data.Traversable (class Traversable, traverse, sequence) -- | `ZipList` is a newtype around `List` which provides a zippy -- | `Applicative` instance. diff --git a/test/Test/Data/List.purs b/test/Test/Data/List.purs index 839d74b..51045fe 100644 --- a/test/Test/Data/List.purs +++ b/test/Test/Data/List.purs @@ -1,11 +1,11 @@ module Test.Data.List (testList) where -import Prelude +import Prelude (Unit, (*), zero, (/=), mod, (+), (==), ($), bind, pure, void, show, (<), (&&), compare, flip, const, (<<<), map, negate) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Console (CONSOLE(), log) -import Data.Foldable -import Data.Monoid.Additive -import Data.List +import Data.Foldable (foldMap, foldl) +import Data.Monoid.Additive (Additive(Additive)) +import Data.List (List(Nil, Cons), (..), length, 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, filterM, filter, concat, concatMap, reverse, alterAt, modifyAt, updateAt, deleteAt, insertAt, findLastIndex, findIndex, elemLastIndex, elemIndex, (!!), uncons, init, tail, last, head, insertBy, insert, snoc, null, replicateM, replicate, singleton, fromFoldable, transpose, (:)) import Data.Maybe (Maybe(..), isNothing) import Data.Maybe.Unsafe (fromJust) import Data.Tuple (Tuple(..)) @@ -120,12 +120,12 @@ testList = do assert $ elemLastIndex 4 (l [1, 2, 1]) == Nothing log "findIndex should return the index of an item that a predicate returns true for in an list" - assert $ findIndex (/= 1) (l [1, 2, 1]) == Just 1 - assert $ findIndex (== 3) (l [1, 2, 1]) == Nothing + assert $ findIndex (_ /= 1) (l [1, 2, 1]) == Just 1 + assert $ findIndex (_ == 3) (l [1, 2, 1]) == Nothing log "findLastIndex should return the last index of an item in an list" - assert $ findLastIndex (/= 1) (l [2, 1, 2]) == Just 2 - assert $ findLastIndex (== 3) (l [2, 1, 2]) == Nothing + assert $ findLastIndex (_ /= 1) (l [2, 1, 2]) == Just 2 + assert $ findLastIndex (_ == 3) (l [2, 1, 2]) == Nothing log "insertAt should add an item at the specified index" assert $ (insertAt 0 1 (l [2, 3])) == Just (l [1, 2, 3]) @@ -150,22 +150,22 @@ testList = do assert $ (updateAt 1 9 nil) == Nothing log "modifyAt should update an item at the specified index" - assert $ (modifyAt 0 (+ 1) (l [1, 2, 3])) == Just (l [2, 2, 3]) - assert $ (modifyAt 1 (+ 1) (l [1, 2, 3])) == Just (l [1, 3, 3]) + assert $ (modifyAt 0 (_ + 1) (l [1, 2, 3])) == Just (l [2, 2, 3]) + assert $ (modifyAt 1 (_ + 1) (l [1, 2, 3])) == Just (l [1, 3, 3]) log "modifyAt should return Nothing if the index is out of range" - assert $ (modifyAt 1 (+ 1) nil) == Nothing + assert $ (modifyAt 1 (_ + 1) nil) == Nothing log "alterAt should update an item at the specified index when the function returns Just" - assert $ (alterAt 0 (Just <<< (+ 1)) (l [1, 2, 3])) == Just (l [2, 2, 3]) - assert $ (alterAt 1 (Just <<< (+ 1)) (l [1, 2, 3])) == Just (l [1, 3, 3]) + assert $ (alterAt 0 (Just <<< (_ + 1)) (l [1, 2, 3])) == Just (l [2, 2, 3]) + assert $ (alterAt 1 (Just <<< (_ + 1)) (l [1, 2, 3])) == Just (l [1, 3, 3]) log "alterAt should drop an item at the specified index when the function returns Nothing" assert $ (alterAt 0 (const Nothing) (l [1, 2, 3])) == Just (l [2, 3]) assert $ (alterAt 1 (const Nothing) (l [1, 2, 3])) == Just (l [1, 3]) log "alterAt should return Nothing if the index is out of range" - assert $ (alterAt 1 (Just <<< (+ 1)) nil) == Nothing + assert $ (alterAt 1 (Just <<< (_ + 1)) nil) == Nothing log "reverse should reverse the order of items in an list" assert $ (reverse (l [1, 2, 3])) == l [3, 2, 1] @@ -204,9 +204,9 @@ testList = do assert $ (take 1 nil) == nil log "takeWhile should keep all values that match a predicate from the front of an list" - assert $ (takeWhile (/= 2) (l [1, 2, 3])) == l [1] - assert $ (takeWhile (/= 3) (l [1, 2, 3])) == l [1, 2] - assert $ (takeWhile (/= 1) nil) == nil + assert $ (takeWhile (_ /= 2) (l [1, 2, 3])) == l [1] + assert $ (takeWhile (_ /= 3) (l [1, 2, 3])) == l [1, 2] + assert $ (takeWhile (_ /= 1) nil) == nil log "drop should remove the specified number of items from the front of an list" assert $ (drop 1 (l [1, 2, 3])) == l [2, 3] @@ -214,12 +214,12 @@ testList = do assert $ (drop 1 nil) == nil log "dropWhile should remove all values that match a predicate from the front of an list" - assert $ (dropWhile (/= 1) (l [1, 2, 3])) == l [1, 2, 3] - assert $ (dropWhile (/= 2) (l [1, 2, 3])) == l [2, 3] - assert $ (dropWhile (/= 1) nil) == nil + assert $ (dropWhile (_ /= 1) (l [1, 2, 3])) == l [1, 2, 3] + assert $ (dropWhile (_ /= 2) (l [1, 2, 3])) == l [2, 3] + assert $ (dropWhile (_ /= 1) nil) == nil log "span should split an list in two based on a predicate" - let spanResult = span (< 4) (l [1, 2, 3, 4, 5, 6, 7]) + let spanResult = span (_ < 4) (l [1, 2, 3, 4, 5, 6, 7]) assert $ spanResult.init == l [1, 2, 3] assert $ spanResult.rest == l [4, 5, 6, 7] diff --git a/test/Test/Data/List/Lazy.purs b/test/Test/Data/List/Lazy.purs index 70c7a2c..28f055f 100644 --- a/test/Test/Data/List/Lazy.purs +++ b/test/Test/Data/List/Lazy.purs @@ -1,9 +1,9 @@ module Test.Data.List.Lazy (testListLazy) where -import Prelude +import Prelude (Unit, (*), zero, (/=), mod, (==), ($), bind, show, (<), (&&), map, const, (+), (<<<), negate, compare, flip) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Console (CONSOLE(), log) -import Data.List.Lazy +import Data.List.Lazy (List, nil, cons, zip, zipWith, intersectBy, intersect, (\\), deleteBy, delete, unionBy, union, nubBy, nub, groupBy, group, span, dropWhile, drop, takeWhile, take, catMaybes, mapMaybe, range, filter, concat, concatMap, reverse, alterAt, modifyAt, updateAt, deleteAt, insertAt, (!!), uncons, init, tail, last, head, insertBy, insert, length, null, singleton, fromFoldable, transpose, (:)) import Data.Maybe (Maybe(..), isNothing) import Data.Maybe.Unsafe (fromJust) import Data.Tuple (Tuple(..)) @@ -136,12 +136,12 @@ testListLazy = do assert $ (updateAt 1 9 (l [1, 2, 3])) == (l [1, 9, 3]) log "modifyAt should update an item at the specified index" - assert $ (modifyAt 0 (+ 1) (l [1, 2, 3])) == (l [2, 2, 3]) - assert $ (modifyAt 1 (+ 1) (l [1, 2, 3])) == (l [1, 3, 3]) + assert $ (modifyAt 0 (_ + 1) (l [1, 2, 3])) == (l [2, 2, 3]) + assert $ (modifyAt 1 (_ + 1) (l [1, 2, 3])) == (l [1, 3, 3]) log "alterAt should update an item at the specified index when the function returns Just" - assert $ (alterAt 0 (Just <<< (+ 1)) (l [1, 2, 3])) == (l [2, 2, 3]) - assert $ (alterAt 1 (Just <<< (+ 1)) (l [1, 2, 3])) == (l [1, 3, 3]) + assert $ (alterAt 0 (Just <<< (_ + 1)) (l [1, 2, 3])) == (l [2, 2, 3]) + assert $ (alterAt 1 (Just <<< (_ + 1)) (l [1, 2, 3])) == (l [1, 3, 3]) log "alterAt should drop an item at the specified index when the function returns Nothing" assert $ (alterAt 0 (const Nothing) (l [1, 2, 3])) == (l [2, 3]) @@ -184,9 +184,9 @@ testListLazy = do assert $ (take 1 nil') == nil' log "takeWhile should keep all values that match a predicate from the front of an list" - assert $ (takeWhile (/= 2) (l [1, 2, 3])) == l [1] - assert $ (takeWhile (/= 3) (l [1, 2, 3])) == l [1, 2] - assert $ (takeWhile (/= 1) nil') == nil' + assert $ (takeWhile (_ /= 2) (l [1, 2, 3])) == l [1] + assert $ (takeWhile (_ /= 3) (l [1, 2, 3])) == l [1, 2] + assert $ (takeWhile (_ /= 1) nil') == nil' log "drop should remove the specified number of items from the front of an list" assert $ (drop 1 (l [1, 2, 3])) == l [2, 3] @@ -194,12 +194,12 @@ testListLazy = do assert $ (drop 1 nil') == nil' log "dropWhile should remove all values that match a predicate from the front of an list" - assert $ (dropWhile (/= 1) (l [1, 2, 3])) == l [1, 2, 3] - assert $ (dropWhile (/= 2) (l [1, 2, 3])) == l [2, 3] - assert $ (dropWhile (/= 1) nil') == nil' + assert $ (dropWhile (_ /= 1) (l [1, 2, 3])) == l [1, 2, 3] + assert $ (dropWhile (_ /= 2) (l [1, 2, 3])) == l [2, 3] + assert $ (dropWhile (_ /= 1) nil') == nil' log "span should split an list in two based on a predicate" - let spanResult = span (< 4) (l [1, 2, 3, 4, 5, 6, 7]) + let spanResult = span (_ < 4) (l [1, 2, 3, 4, 5, 6, 7]) assert $ spanResult.init == l [1, 2, 3] assert $ spanResult.rest == l [4, 5, 6, 7] diff --git a/test/Test/Data/List/Unsafe.purs b/test/Test/Data/List/Unsafe.purs index 12ea12d..261297d 100644 --- a/test/Test/Data/List/Unsafe.purs +++ b/test/Test/Data/List/Unsafe.purs @@ -1,10 +1,10 @@ module Test.Data.List.Unsafe (testListUnsafe) where -import Prelude +import Prelude (Unit, bind, (==), ($)) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Console (CONSOLE(), log) import Data.List (List(..), fromFoldable) -import Data.List.Unsafe +import Data.List.Unsafe (init, tail, last, head) import Test.Assert (ASSERT(), assert, assertThrows) testListUnsafe :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit diff --git a/test/Test/Data/List/ZipList.purs b/test/Test/Data/List/ZipList.purs index 4d5d03a..48b387b 100644 --- a/test/Test/Data/List/ZipList.purs +++ b/test/Test/Data/List/ZipList.purs @@ -1,15 +1,10 @@ module Test.Data.List.ZipList (testZipList) where -import Prelude +import Prelude (class Eq, Unit, (<<<), (<*>), (<$>), (==), ($), const, (*), bind, (+)) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Console (CONSOLE(), log) -import Data.Foldable -import Data.Monoid.Additive import Data.List.Lazy as LazyList import Data.List.ZipList (ZipList(..)) -import Data.Maybe (Maybe(..), isNothing) -import Data.Maybe.Unsafe (fromJust) -import Data.Tuple (Tuple(..)) import Data.Array as Array import Test.Assert (ASSERT(), assert) diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 30f4284..fef0e3d 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -1,13 +1,13 @@ module Test.Main where -import Prelude +import Prelude (Unit, bind) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Console (CONSOLE()) import Test.Assert (ASSERT()) -import Test.Data.List -import Test.Data.List.Lazy -import Test.Data.List.ZipList -import Test.Data.List.Unsafe +import Test.Data.List (testList) +import Test.Data.List.Lazy (testListLazy) +import Test.Data.List.ZipList (testZipList) +import Test.Data.List.Unsafe (testListUnsafe) main :: forall eff. Eff (assert :: ASSERT, console :: CONSOLE | eff) Unit main = do