Skip to content

Commit 14617c9

Browse files
committed
Refactor functors and related packages
This is part of a set of commits that rearrange the dependencies between multiple packages. The immediate motivation is to allow certain newtypes to be reused between `profunctor` and `bifunctors`, but this particular approach goes a little beyond that in two ways: first, it attempts to move data types (`either`, `tuple`) toward the bottom of the dependency stack; and second, it tries to ensure no package comes between `functors` and the packages most closely related to it, in order to open the possibility of merging those packages together (which may be desirable if at some point in the future additional newtypes are added which reveal new and exciting constraints on the module dependency graph).
1 parent 4a03126 commit 14617c9

File tree

3 files changed

+1
-57
lines changed

3 files changed

+1
-57
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Breaking changes:
1111
New features:
1212
- Added `\/` alias for `either` (#51)
1313
- Added lazy versions of `fromRight` and `fromLeft` (#59)
14+
- This package no longer depends on the `purescript-bifunctors` and `purescript-foldable-traversable` packages. Relevant instances have been moved to those packages. (TBD)
1415

1516
Bugfixes:
1617

bower.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-bifunctors": "master",
2019
"purescript-control": "master",
21-
"purescript-foldable-traversable": "master",
2220
"purescript-invariant": "master",
2321
"purescript-maybe": "master",
2422
"purescript-prelude": "master"

src/Data/Either.purs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@ import Prelude
44

55
import Control.Alt (class Alt, (<|>))
66
import Control.Extend (class Extend)
7-
import Data.Bifoldable (class Bifoldable)
8-
import Data.Bifunctor (class Bifunctor)
9-
import Data.Bitraversable (class Bitraversable)
107
import Data.Eq (class Eq1)
11-
import Data.Foldable (class Foldable)
12-
import Data.FoldableWithIndex (class FoldableWithIndex)
138
import Data.Functor.Invariant (class Invariant, imapF)
14-
import Data.FunctorWithIndex (class FunctorWithIndex)
159
import Data.Generic.Rep (class Generic)
1610
import Data.Maybe (Maybe(..), maybe, maybe')
1711
import Data.Ord (class Ord1)
18-
import Data.Traversable (class Traversable)
19-
import Data.TraversableWithIndex (class TraversableWithIndex)
2012

2113
-- | The `Either` type is used to represent a choice between two types of value.
2214
-- |
@@ -38,18 +30,11 @@ data Either a b = Left a | Right b
3830
-- | ```
3931
derive instance functorEither :: Functor (Either a)
4032

41-
instance functorWithIndexEither :: FunctorWithIndex Unit (Either a) where
42-
mapWithIndex f = map $ f unit
43-
4433
derive instance genericEither :: Generic (Either a b) _
4534

4635
instance invariantEither :: Invariant (Either a) where
4736
imap = imapF
4837

49-
instance bifunctorEither :: Bifunctor Either where
50-
bimap f _ (Left l) = Left (f l)
51-
bimap _ g (Right r) = Right (g r)
52-
5338
-- | The `Apply` instance allows functions contained within a `Right` to
5439
-- | transform a value contained within a `Right` using the `(<*>)` operator:
5540
-- |
@@ -209,46 +194,6 @@ instance boundedEither :: (Bounded a, Bounded b) => Bounded (Either a b) where
209194
top = Right top
210195
bottom = Left bottom
211196

212-
instance foldableEither :: Foldable (Either a) where
213-
foldr _ z (Left _) = z
214-
foldr f z (Right x) = f x z
215-
foldl _ z (Left _) = z
216-
foldl f z (Right x) = f z x
217-
foldMap f (Left _) = mempty
218-
foldMap f (Right x) = f x
219-
220-
instance foldableWithIndexEither :: FoldableWithIndex Unit (Either a) where
221-
foldrWithIndex _ z (Left _) = z
222-
foldrWithIndex f z (Right x) = f unit x z
223-
foldlWithIndex _ z (Left _) = z
224-
foldlWithIndex f z (Right x) = f unit z x
225-
foldMapWithIndex f (Left _) = mempty
226-
foldMapWithIndex f (Right x) = f unit x
227-
228-
instance bifoldableEither :: Bifoldable Either where
229-
bifoldr f _ z (Left a) = f a z
230-
bifoldr _ g z (Right b) = g b z
231-
bifoldl f _ z (Left a) = f z a
232-
bifoldl _ g z (Right b) = g z b
233-
bifoldMap f _ (Left a) = f a
234-
bifoldMap _ g (Right b) = g b
235-
236-
instance traversableEither :: Traversable (Either a) where
237-
traverse _ (Left x) = pure (Left x)
238-
traverse f (Right x) = Right <$> f x
239-
sequence (Left x) = pure (Left x)
240-
sequence (Right x) = Right <$> x
241-
242-
instance traversableWithIndexEither :: TraversableWithIndex Unit (Either a) where
243-
traverseWithIndex _ (Left x) = pure (Left x)
244-
traverseWithIndex f (Right x) = Right <$> f unit x
245-
246-
instance bitraversableEither :: Bitraversable Either where
247-
bitraverse f _ (Left a) = Left <$> f a
248-
bitraverse _ g (Right b) = Right <$> g b
249-
bisequence (Left a) = Left <$> a
250-
bisequence (Right b) = Right <$> b
251-
252197
instance semigroupEither :: (Semigroup b) => Semigroup (Either a b) where
253198
append x y = append <$> x <*> y
254199

0 commit comments

Comments
 (0)