Skip to content

Commit ffc9a6b

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 cac075c commit ffc9a6b

File tree

3 files changed

+3
-79
lines changed

3 files changed

+3
-79
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ Notable changes to this project are documented in this file. The format is based
66

77
Breaking changes:
88
- Added support for PureScript 0.14 and dropped support for all previous versions (#37, #43)
9+
- `Data.Tuple.lookup` has been moved to `Data.Foldable.lookup` in the `purescript-foldable-traversable` package (#46)
910

1011
New features:
1112
- Added Generic instance for Tuple (#40)
13+
- This package no longer depends on the `purescript-bifunctors`, `purescript-distributive`, `purescript-foldable-traversable`, `purescript-maybe`, `purescript-newtype`, and `purescript-type-equality` packages. Relevant instances have been moved to those packages. (#46)
1214

1315
Bugfixes:
1416

bower.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-bifunctors": "master",
2019
"purescript-control": "master",
21-
"purescript-distributive": "master",
22-
"purescript-foldable-traversable": "master",
2320
"purescript-invariant": "master",
24-
"purescript-maybe": "master",
25-
"purescript-newtype": "master",
26-
"purescript-prelude": "master",
27-
"purescript-type-equality": "master"
21+
"purescript-prelude": "master"
2822
}
2923
}

src/Data/Tuple.purs

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,14 @@ module Data.Tuple where
33

44
import Prelude
55

6-
import Control.Biapplicative (class Biapplicative)
7-
import Control.Biapply (class Biapply)
86
import Control.Comonad (class Comonad)
97
import Control.Extend (class Extend)
108
import Control.Lazy (class Lazy, defer)
11-
import Data.Bifoldable (class Bifoldable)
12-
import Data.Bifunctor (class Bifunctor)
13-
import Data.Bitraversable (class Bitraversable)
14-
import Data.Distributive (class Distributive, collectDefault)
159
import Data.Eq (class Eq1)
16-
import Data.Foldable (class Foldable, foldMap)
17-
import Data.FoldableWithIndex (class FoldableWithIndex)
1810
import Data.Functor.Invariant (class Invariant, imapF)
19-
import Data.FunctorWithIndex (class FunctorWithIndex)
2011
import Data.Generic.Rep (class Generic)
2112
import Data.HeytingAlgebra (implies, ff, tt)
22-
import Data.Maybe (Maybe(..))
23-
import Data.Maybe.First (First(..))
24-
import Data.Newtype (unwrap)
2513
import Data.Ord (class Ord1)
26-
import Data.Semigroup.Foldable (class Foldable1)
27-
import Data.Semigroup.Traversable (class Traversable1)
28-
import Data.Traversable (class Traversable)
29-
import Data.TraversableWithIndex (class TraversableWithIndex)
30-
import Type.Equality (class TypeEquals, from)
3114

3215
-- | A simple product type for wrapping a pair of component values.
3316
data Tuple a b = Tuple a b
@@ -99,17 +82,11 @@ instance booleanAlgebraTuple :: (BooleanAlgebra a, BooleanAlgebra b) => BooleanA
9982
-- | ````
10083
derive instance functorTuple :: Functor (Tuple a)
10184

102-
instance functorWithIndexTuple :: FunctorWithIndex Unit (Tuple a) where
103-
mapWithIndex f = map $ f unit
104-
10585
derive instance genericTuple :: Generic (Tuple a b) _
10686

10787
instance invariantTuple :: Invariant (Tuple a) where
10888
imap = imapF
10989

110-
instance bifunctorTuple :: Bifunctor Tuple where
111-
bimap f g (Tuple x y) = Tuple (f x) (g y)
112-
11390
-- | The `Apply` instance allows functions to transform the contents of a
11491
-- | `Tuple` with the `<*>` operator whenever there is a `Semigroup` instance
11592
-- | for the `fst` component, so:
@@ -119,15 +96,9 @@ instance bifunctorTuple :: Bifunctor Tuple where
11996
instance applyTuple :: (Semigroup a) => Apply (Tuple a) where
12097
apply (Tuple a1 f) (Tuple a2 x) = Tuple (a1 <> a2) (f x)
12198

122-
instance biapplyTuple :: Biapply Tuple where
123-
biapply (Tuple f g) (Tuple a b) = Tuple (f a) (g b)
124-
12599
instance applicativeTuple :: (Monoid a) => Applicative (Tuple a) where
126100
pure = Tuple mempty
127101

128-
instance biapplicativeTuple :: Biapplicative Tuple where
129-
bipure = Tuple
130-
131102
instance bindTuple :: (Semigroup a) => Bind (Tuple a) where
132103
bind (Tuple a1 b) f = case f b of
133104
Tuple a2 c -> Tuple (a1 <> a2) c
@@ -143,45 +114,6 @@ instance comonadTuple :: Comonad (Tuple a) where
143114
instance lazyTuple :: (Lazy a, Lazy b) => Lazy (Tuple a b) where
144115
defer f = Tuple (defer $ \_ -> fst (f unit)) (defer $ \_ -> snd (f unit))
145116

146-
instance foldableTuple :: Foldable (Tuple a) where
147-
foldr f z (Tuple _ x) = f x z
148-
foldl f z (Tuple _ x) = f z x
149-
foldMap f (Tuple _ x) = f x
150-
151-
instance foldable1Tuple :: Foldable1 (Tuple a) where
152-
foldMap1 f (Tuple _ x) = f x
153-
foldr1 _ (Tuple _ x) = x
154-
foldl1 _ (Tuple _ x) = x
155-
156-
instance foldableWithIndexTuple :: FoldableWithIndex Unit (Tuple a) where
157-
foldrWithIndex f z (Tuple _ x) = f unit x z
158-
foldlWithIndex f z (Tuple _ x) = f unit z x
159-
foldMapWithIndex f (Tuple _ x) = f unit x
160-
161-
instance bifoldableTuple :: Bifoldable Tuple where
162-
bifoldMap f g (Tuple a b) = f a <> g b
163-
bifoldr f g z (Tuple a b) = f a (g b z)
164-
bifoldl f g z (Tuple a b) = g (f z a) b
165-
166-
instance traversableTuple :: Traversable (Tuple a) where
167-
traverse f (Tuple x y) = Tuple x <$> f y
168-
sequence (Tuple x y) = Tuple x <$> y
169-
170-
instance traversable1Tuple :: Traversable1 (Tuple a) where
171-
traverse1 f (Tuple x y) = Tuple x <$> f y
172-
sequence1 (Tuple x y) = Tuple x <$> y
173-
174-
instance traversableWithIndexTuple :: TraversableWithIndex Unit (Tuple a) where
175-
traverseWithIndex f (Tuple x y) = Tuple x <$> f unit y
176-
177-
instance bitraversableTuple :: Bitraversable Tuple where
178-
bitraverse f g (Tuple a b) = Tuple <$> f a <*> g b
179-
bisequence (Tuple a b) = Tuple <$> a <*> b
180-
181-
instance distributiveTuple :: TypeEquals a Unit => Distributive (Tuple a) where
182-
collect = collectDefault
183-
distribute = Tuple (from unit) <<< map snd
184-
185117
-- | Returns the first component of a tuple.
186118
fst :: forall a b. Tuple a b -> a
187119
fst (Tuple a _) = a
@@ -201,7 +133,3 @@ uncurry f (Tuple a b) = f a b
201133
-- | Exchange the first and second components of a tuple.
202134
swap :: forall a b. Tuple a b -> Tuple b a
203135
swap (Tuple a b) = Tuple b a
204-
205-
-- | Lookup a value in a data structure of `Tuple`s, generalizing association lists.
206-
lookup :: forall a b f. Foldable f => Eq a => a -> f (Tuple a b) -> Maybe b
207-
lookup a = unwrap <<< foldMap \(Tuple a' b) -> First (if a == a' then Just b else Nothing)

0 commit comments

Comments
 (0)