Skip to content

Commit 186b949

Browse files
committed
Merge pull request #51 from hdgarrood/rename
Improve names for toList, fromList.
2 parents 39ab01e + 32799ce commit 186b949

File tree

8 files changed

+334
-274
lines changed

8 files changed

+334
-274
lines changed

docs/Data/List.md

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,39 @@ which case it consists of a head element, and another list (represented by the
2525

2626
##### Instances
2727
``` purescript
28-
instance showList :: (Show a) => Show (List a)
29-
instance eqList :: (Eq a) => Eq (List a)
30-
instance ordList :: (Ord a) => Ord (List a)
31-
instance semigroupList :: Semigroup (List a)
32-
instance monoidList :: Monoid (List a)
33-
instance functorList :: Functor List
34-
instance foldableList :: Foldable List
35-
instance unfoldableList :: Unfoldable List
36-
instance traversableList :: Traversable List
37-
instance applyList :: Apply List
38-
instance applicativeList :: Applicative List
39-
instance bindList :: Bind List
40-
instance monadList :: Monad List
41-
instance altList :: Alt List
42-
instance plusList :: Plus List
43-
instance alternativeList :: Alternative List
44-
instance monadPlusList :: MonadPlus List
28+
(Show a) => Show (List a)
29+
(Eq a) => Eq (List a)
30+
(Ord a) => Ord (List a)
31+
Semigroup (List a)
32+
Monoid (List a)
33+
Functor List
34+
Foldable List
35+
Unfoldable List
36+
Traversable List
37+
Apply List
38+
Applicative List
39+
Bind List
40+
Monad List
41+
Alt List
42+
Plus List
43+
Alternative List
44+
MonadPlus List
4545
```
4646

47-
#### `fromList`
47+
#### `toUnfoldable`
4848

4949
``` purescript
50-
fromList :: forall f a. (Unfoldable f) => List a -> f a
50+
toUnfoldable :: forall f a. (Unfoldable f) => List a -> f a
5151
```
5252

5353
Convert a list into any unfoldable structure.
5454

5555
Running time: `O(n)`
5656

57-
#### `toList`
57+
#### `fromFoldable`
5858

5959
``` purescript
60-
toList :: forall f a. (Foldable f) => f a -> List a
60+
fromFoldable :: forall f a. (Foldable f) => f a -> List a
6161
```
6262

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

665+
#### `toList`
666+
667+
``` purescript
668+
toList :: forall f a. (Foldable f) => f a -> List a
669+
```
670+
671+
*Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
672+
later version.
673+
674+
#### `fromList`
675+
676+
``` purescript
677+
fromList :: forall f a. (Unfoldable f) => List a -> f a
678+
```
679+
680+
*Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
681+
later version.
682+
665683

docs/Data/List/Lazy.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ A lazy linked list.
2020

2121
##### Instances
2222
``` purescript
23-
instance showList :: (Show a) => Show (List a)
24-
instance eqList :: (Eq a) => Eq (List a)
25-
instance ordList :: (Ord a) => Ord (List a)
26-
instance lazyList :: Lazy (List a)
27-
instance semigroupList :: Semigroup (List a)
28-
instance monoidList :: Monoid (List a)
29-
instance functorList :: Functor List
30-
instance foldableList :: Foldable List
31-
instance unfoldableList :: Unfoldable List
32-
instance traversableList :: Traversable List
33-
instance applyList :: Apply List
34-
instance applicativeList :: Applicative List
35-
instance bindList :: Bind List
36-
instance monadList :: Monad List
37-
instance altList :: Alt List
38-
instance plusList :: Plus List
39-
instance alternativeList :: Alternative List
40-
instance monadPlusList :: MonadPlus List
23+
(Show a) => Show (List a)
24+
(Eq a) => Eq (List a)
25+
(Ord a) => Ord (List a)
26+
Lazy (List a)
27+
Semigroup (List a)
28+
Monoid (List a)
29+
Functor List
30+
Foldable List
31+
Unfoldable List
32+
Traversable List
33+
Apply List
34+
Applicative List
35+
Bind List
36+
Monad List
37+
Alt List
38+
Plus List
39+
Alternative List
40+
MonadPlus List
4141
```
4242

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

4949
Unwrap a lazy linked list
5050

51-
#### `fromList`
51+
#### `toUnfoldable`
5252

5353
``` purescript
54-
fromList :: forall f a. (Unfoldable f) => List a -> f a
54+
toUnfoldable :: forall f a. (Unfoldable f) => List a -> f a
5555
```
5656

5757
Convert a list into any unfoldable structure.
5858

5959
Running time: `O(n)`
6060

61-
#### `toList`
61+
#### `fromFoldable`
6262

6363
``` purescript
64-
toList :: forall f a. (Foldable f) => f a -> List a
64+
fromFoldable :: forall f a. (Foldable f) => f a -> List a
6565
```
6666

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

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

587+
#### `toList`
588+
589+
``` purescript
590+
toList :: forall f a. (Foldable f) => f a -> List a
591+
```
592+
593+
*Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
594+
later version.
595+
596+
#### `fromList`
597+
598+
``` purescript
599+
fromList :: forall f a. (Unfoldable f) => List a -> f a
600+
```
601+
602+
*Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
603+
later version.
604+
587605

docs/Data/List/ZipList.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ newtype ZipList a
1515

1616
##### Instances
1717
``` purescript
18-
instance showZipList :: (Show a) => Show (ZipList a)
19-
instance eqZipList :: (Eq a) => Eq (ZipList a)
20-
instance ordZipList :: (Ord a) => Ord (ZipList a)
21-
instance semigroupZipList :: Semigroup (ZipList a)
22-
instance monoidZipList :: Monoid (ZipList a)
23-
instance foldableZipList :: Foldable ZipList
24-
instance traversableZipList :: Traversable ZipList
25-
instance functorZipList :: Functor ZipList
26-
instance applyZipList :: Apply ZipList
27-
instance applicativeZipList :: Applicative ZipList
28-
instance altZipList :: Alt ZipList
29-
instance plusZipList :: Plus ZipList
30-
instance alternativeZipList :: Alternative ZipList
18+
(Show a) => Show (ZipList a)
19+
(Eq a) => Eq (ZipList a)
20+
(Ord a) => Ord (ZipList a)
21+
Semigroup (ZipList a)
22+
Monoid (ZipList a)
23+
Foldable ZipList
24+
Traversable ZipList
25+
Functor ZipList
26+
Apply ZipList
27+
Applicative ZipList
28+
Alt ZipList
29+
Plus ZipList
30+
Alternative ZipList
3131
```
3232

3333
#### `runZipList`

src/Data/List.purs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
module Data.List
1111
( List(..)
12-
, fromList
13-
, toList
12+
, toUnfoldable
13+
, fromFoldable
1414

1515
, singleton
1616
, (..), range
@@ -81,6 +81,9 @@ module Data.List
8181
, unzip
8282

8383
, foldM
84+
85+
, toList
86+
, fromList
8487
) where
8588

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

114117
-- | Construct a list from a foldable structure.
115118
-- |
116119
-- | Running time: `O(n)`
117-
toList :: forall f a. (Foldable f) => f a -> List a
118-
toList = foldr Cons Nil
120+
fromFoldable :: forall f a. (Foldable f) => f a -> List a
121+
fromFoldable = foldr Cons Nil
119122

120123
--------------------------------------------------------------------------------
121124
-- List creation ---------------------------------------------------------------
@@ -680,6 +683,16 @@ foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> List b -> m a
680683
foldM _ a Nil = return a
681684
foldM f a (Cons b bs) = f a b >>= \a' -> foldM f a' bs
682685

686+
-- | *Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
687+
-- | later version.
688+
toList :: forall f a. (Foldable f) => f a -> List a
689+
toList = fromFoldable
690+
691+
-- | *Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
692+
-- | later version.
693+
fromList :: forall f a. (Unfoldable f) => List a -> f a
694+
fromList = toUnfoldable
695+
683696
--------------------------------------------------------------------------------
684697
-- Instances -------------------------------------------------------------------
685698
--------------------------------------------------------------------------------

src/Data/List/Lazy.purs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
module Data.List.Lazy
1111
( List(..)
1212
, runList
13-
, fromList
14-
, toList
13+
, toUnfoldable
14+
, fromFoldable
1515
, Step(..)
1616
, step
1717
, nil
@@ -88,6 +88,8 @@ module Data.List.Lazy
8888
-- , unzip
8989

9090
-- , foldM
91+
, toList
92+
, fromList
9193
) where
9294

9395
import Prelude
@@ -117,14 +119,14 @@ runList (List l) = l
117119
-- | Convert a list into any unfoldable structure.
118120
-- |
119121
-- | Running time: `O(n)`
120-
fromList :: forall f a. (Unfoldable f) => List a -> f a
121-
fromList = unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs)
122+
toUnfoldable :: forall f a. (Unfoldable f) => List a -> f a
123+
toUnfoldable = unfoldr (\xs -> (\rec -> Tuple rec.head rec.tail) <$> uncons xs)
122124

123125
-- | Construct a list from a foldable structure.
124126
-- |
125127
-- | Running time: `O(n)`
126-
toList :: forall f a. (Foldable f) => f a -> List a
127-
toList = foldr cons nil
128+
fromFoldable :: forall f a. (Foldable f) => f a -> List a
129+
fromFoldable = foldr cons nil
128130

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

624-
--------------------------------------------------------------------------------
625-
-- Folding ---------------------------------------------------------------------
626-
--------------------------------------------------------------------------------
626+
-- | *Deprecated.* Use `fromFoldable` instead. `toList` will be removed in a
627+
-- | later version.
628+
toList :: forall f a. (Foldable f) => f a -> List a
629+
toList = fromFoldable
630+
631+
-- | *Deprecated.* Use `toUnfoldable` instead. `fromList` will be removed in a
632+
-- | later version.
633+
fromList :: forall f a. (Unfoldable f) => List a -> f a
634+
fromList = toUnfoldable
627635

628636
--------------------------------------------------------------------------------
629637
-- Instances -------------------------------------------------------------------

0 commit comments

Comments
 (0)