Skip to content

Commit

Permalink
Merge pull request #51 from hdgarrood/rename
Browse files Browse the repository at this point in the history
Improve names for toList, fromList.
  • Loading branch information
paf31 committed Jan 11, 2016
2 parents 39ab01e + 32799ce commit 186b949
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 274 deletions.
60 changes: 39 additions & 21 deletions docs/Data/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,39 @@ which case it consists of a head element, and another list (represented by the

##### Instances
``` purescript
instance showList :: (Show a) => Show (List a)
instance eqList :: (Eq a) => Eq (List a)
instance ordList :: (Ord a) => Ord (List a)
instance semigroupList :: Semigroup (List a)
instance monoidList :: Monoid (List a)
instance functorList :: Functor List
instance foldableList :: Foldable List
instance unfoldableList :: Unfoldable List
instance traversableList :: Traversable List
instance applyList :: Apply List
instance applicativeList :: Applicative List
instance bindList :: Bind List
instance monadList :: Monad List
instance altList :: Alt List
instance plusList :: Plus List
instance alternativeList :: Alternative List
instance monadPlusList :: MonadPlus List
(Show a) => Show (List a)
(Eq a) => Eq (List a)
(Ord a) => Ord (List a)
Semigroup (List a)
Monoid (List a)
Functor List
Foldable List
Unfoldable List
Traversable List
Apply List
Applicative List
Bind List
Monad List
Alt List
Plus List
Alternative List
MonadPlus List
```

#### `fromList`
#### `toUnfoldable`

``` purescript
fromList :: forall f a. (Unfoldable f) => List a -> f a
toUnfoldable :: forall f a. (Unfoldable f) => List a -> f a
```

Convert a list into any unfoldable structure.

Running time: `O(n)`

#### `toList`
#### `fromFoldable`

``` purescript
toList :: forall f a. (Foldable f) => f a -> List a
fromFoldable :: forall f a. (Foldable f) => f a -> List a
```

Construct a list from a foldable structure.
Expand Down Expand Up @@ -662,4 +662,22 @@ second components.
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> List b -> m a
```

#### `toList`

``` purescript
toList :: forall f a. (Foldable f) => f a -> List a
```

*Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
later version.

#### `fromList`

``` purescript
fromList :: forall f a. (Unfoldable f) => List a -> f a
```

*Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
later version.


62 changes: 40 additions & 22 deletions docs/Data/List/Lazy.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ A lazy linked list.

##### Instances
``` purescript
instance showList :: (Show a) => Show (List a)
instance eqList :: (Eq a) => Eq (List a)
instance ordList :: (Ord a) => Ord (List a)
instance lazyList :: Lazy (List a)
instance semigroupList :: Semigroup (List a)
instance monoidList :: Monoid (List a)
instance functorList :: Functor List
instance foldableList :: Foldable List
instance unfoldableList :: Unfoldable List
instance traversableList :: Traversable List
instance applyList :: Apply List
instance applicativeList :: Applicative List
instance bindList :: Bind List
instance monadList :: Monad List
instance altList :: Alt List
instance plusList :: Plus List
instance alternativeList :: Alternative List
instance monadPlusList :: MonadPlus List
(Show a) => Show (List a)
(Eq a) => Eq (List a)
(Ord a) => Ord (List a)
Lazy (List a)
Semigroup (List a)
Monoid (List a)
Functor List
Foldable List
Unfoldable List
Traversable List
Apply List
Applicative List
Bind List
Monad List
Alt List
Plus List
Alternative List
MonadPlus List
```

#### `runList`
Expand All @@ -48,20 +48,20 @@ runList :: forall a. List a -> Lazy (Step a)

Unwrap a lazy linked list

#### `fromList`
#### `toUnfoldable`

``` purescript
fromList :: forall f a. (Unfoldable f) => List a -> f a
toUnfoldable :: forall f a. (Unfoldable f) => List a -> f a
```

Convert a list into any unfoldable structure.

Running time: `O(n)`

#### `toList`
#### `fromFoldable`

``` purescript
toList :: forall f a. (Foldable f) => f a -> List a
fromFoldable :: forall f a. (Foldable f) => f a -> List a
```

Construct a list from a foldable structure.
Expand Down Expand Up @@ -584,4 +584,22 @@ Collect pairs of elements at the same positions in two lists.

Running time: `O(min(m, n))`

#### `toList`

``` purescript
toList :: forall f a. (Foldable f) => f a -> List a
```

*Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
later version.

#### `fromList`

``` purescript
fromList :: forall f a. (Unfoldable f) => List a -> f a
```

*Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
later version.


26 changes: 13 additions & 13 deletions docs/Data/List/ZipList.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ newtype ZipList a

##### Instances
``` purescript
instance showZipList :: (Show a) => Show (ZipList a)
instance eqZipList :: (Eq a) => Eq (ZipList a)
instance ordZipList :: (Ord a) => Ord (ZipList a)
instance semigroupZipList :: Semigroup (ZipList a)
instance monoidZipList :: Monoid (ZipList a)
instance foldableZipList :: Foldable ZipList
instance traversableZipList :: Traversable ZipList
instance functorZipList :: Functor ZipList
instance applyZipList :: Apply ZipList
instance applicativeZipList :: Applicative ZipList
instance altZipList :: Alt ZipList
instance plusZipList :: Plus ZipList
instance alternativeZipList :: Alternative ZipList
(Show a) => Show (ZipList a)
(Eq a) => Eq (ZipList a)
(Ord a) => Ord (ZipList a)
Semigroup (ZipList a)
Monoid (ZipList a)
Foldable ZipList
Traversable ZipList
Functor ZipList
Apply ZipList
Applicative ZipList
Alt ZipList
Plus ZipList
Alternative ZipList
```

#### `runZipList`
Expand Down
25 changes: 19 additions & 6 deletions src/Data/List.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

module Data.List
( List(..)
, fromList
, toList
, toUnfoldable
, fromFoldable

, singleton
, (..), range
Expand Down Expand Up @@ -81,6 +81,9 @@ module Data.List
, unzip

, foldM

, toList
, fromList
) where

import Prelude
Expand Down Expand Up @@ -108,14 +111,14 @@ data List a = Nil | Cons a (List a)
-- | Convert a list into any unfoldable structure.
-- |
-- | Running time: `O(n)`
fromList :: forall f a. (Unfoldable f) => List a -> f a
fromList = unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs)
toUnfoldable :: forall f a. (Unfoldable f) => List a -> f a
toUnfoldable = unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs)

-- | Construct a list from a foldable structure.
-- |
-- | Running time: `O(n)`
toList :: forall f a. (Foldable f) => f a -> List a
toList = foldr Cons Nil
fromFoldable :: forall f a. (Foldable f) => f a -> List a
fromFoldable = foldr Cons Nil

--------------------------------------------------------------------------------
-- List creation ---------------------------------------------------------------
Expand Down Expand Up @@ -680,6 +683,16 @@ foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> List b -> m a
foldM _ a Nil = return a
foldM f a (Cons b bs) = f a b >>= \a' -> foldM f a' bs

-- | *Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
-- | later version.
toList :: forall f a. (Foldable f) => f a -> List a
toList = fromFoldable

-- | *Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
-- | later version.
fromList :: forall f a. (Unfoldable f) => List a -> f a
fromList = toUnfoldable

--------------------------------------------------------------------------------
-- Instances -------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand Down
26 changes: 17 additions & 9 deletions src/Data/List/Lazy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
module Data.List.Lazy
( List(..)
, runList
, fromList
, toList
, toUnfoldable
, fromFoldable
, Step(..)
, step
, nil
Expand Down Expand Up @@ -88,6 +88,8 @@ module Data.List.Lazy
-- , unzip

-- , foldM
, toList
, fromList
) where

import Prelude
Expand Down Expand Up @@ -117,14 +119,14 @@ runList (List l) = l
-- | Convert a list into any unfoldable structure.
-- |
-- | Running time: `O(n)`
fromList :: forall f a. (Unfoldable f) => List a -> f a
fromList = unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs)
toUnfoldable :: forall f a. (Unfoldable f) => List a -> f a
toUnfoldable = unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs)

-- | Construct a list from a foldable structure.
-- |
-- | Running time: `O(n)`
toList :: forall f a. (Foldable f) => f a -> List a
toList = foldr cons nil
fromFoldable :: forall f a. (Foldable f) => f a -> List a
fromFoldable = foldr cons nil

-- | A list is either empty (represented by the `Nil` constructor) or non-empty, in
-- | which case it consists of a head element, and another list (represented by the
Expand Down Expand Up @@ -621,9 +623,15 @@ zipWith f xs ys = List (go <$> runList xs <*> runList ys)
zip :: forall a b. List a -> List b -> List (Tuple a b)
zip = zipWith Tuple

--------------------------------------------------------------------------------
-- Folding ---------------------------------------------------------------------
--------------------------------------------------------------------------------
-- | *Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
-- | later version.
toList :: forall f a. (Foldable f) => f a -> List a
toList = fromFoldable

-- | *Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
-- | later version.
fromList :: forall f a. (Unfoldable f) => List a -> f a
fromList = toUnfoldable

--------------------------------------------------------------------------------
-- Instances -------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 186b949

Please sign in to comment.