Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactor functors and related packages #22

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Notable changes to this project are documented in this file. The format is based

Breaking changes:
- Added support for PureScript 0.14 and dropped support for all previous versions (#16)
- `Clown`, `Flip`, `Joker`, and `Product` have been moved to the `Data.Functors` module in the `purescript-functors` package, so that the same types can also be used as profunctors; `Product` was renamed to `Product2` (#22)
- `Wrap` was deleted; it is expected that any instances of `Bifunctor` will be accompanied by a corresponding instance of `Functor` (#22)

New features:

Expand All @@ -14,6 +16,7 @@ Bugfixes:
Other improvements:
- Migrated CI to GitHub Actions and updated installation instructions to use Spago (#18)
- Added a CHANGELOG.md file and pull request template (#19, #20)
- This package now depends on the `purescript-const`, `purescript-either`, and `purescript-tuples` packages, and contains instances previously in those packages (#22)

## [v4.0.0](https://github.com/purescript/purescript-bifunctors/releases/tag/v4.0.0) - 2018-05-23

Expand Down
5 changes: 4 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"package.json"
],
"dependencies": {
"purescript-const": "master",
"purescript-either": "master",
"purescript-newtype": "master",
"purescript-prelude": "master",
"purescript-newtype": "master"
"purescript-tuples": "master"
}
}
4 changes: 4 additions & 0 deletions src/Control/Biapplicative.purs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module Control.Biapplicative where

import Control.Biapply (class Biapply)
import Data.Tuple (Tuple(..))

-- | `Biapplicative` captures type constructors of two arguments which support lifting of
-- | functions of zero or more arguments, in the sense of `Applicative`.
class Biapply w <= Biapplicative w where
bipure :: forall a b. a -> b -> w a b

instance biapplicativeTuple :: Biapplicative Tuple where
bipure = Tuple
4 changes: 4 additions & 0 deletions src/Control/Biapply.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Control.Biapply where
import Data.Function (const, identity)

import Data.Bifunctor (class Bifunctor, bimap)
import Data.Tuple (Tuple(..))

-- | A convenience operator which can be used to apply the result of `bipure` in
-- | the style of `Applicative`:
Expand Down Expand Up @@ -53,3 +54,6 @@ bilift3
-> w c g
-> w d h
bilift3 f g a b c = bimap f g <<$>> a <<*>> b <<*>> c

instance biapplyTuple :: Biapply Tuple where
biapply (Tuple f g) (Tuple a b) = Tuple (f a) (g b)
13 changes: 13 additions & 0 deletions src/Data/Bifunctor.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module Data.Bifunctor where

import Control.Category (identity)
import Data.Const (Const(..))
import Data.Either (Either(..))
import Data.Tuple (Tuple(..))

-- | A `Bifunctor` is a `Functor` from the pair category `(Type, Type)` to `Type`.
-- |
Expand All @@ -25,3 +28,13 @@ lmap f = bimap f identity
-- | Map a function over the second type arguments of a `Bifunctor`.
rmap :: forall f a b c. Bifunctor f => (b -> c) -> f a b -> f a c
rmap = bimap identity

instance bifunctorEither :: Bifunctor Either where
bimap f _ (Left l) = Left (f l)
bimap _ g (Right r) = Right (g r)

instance bifunctorTuple :: Bifunctor Tuple where
bimap f g (Tuple x y) = Tuple (f x) (g y)

instance bifunctorConst :: Bifunctor Const where
bimap f _ (Const a) = Const (f a)
34 changes: 0 additions & 34 deletions src/Data/Bifunctor/Clown.purs

This file was deleted.

34 changes: 0 additions & 34 deletions src/Data/Bifunctor/Flip.purs

This file was deleted.

34 changes: 0 additions & 34 deletions src/Data/Bifunctor/Joker.purs

This file was deleted.

28 changes: 0 additions & 28 deletions src/Data/Bifunctor/Product.purs

This file was deleted.

34 changes: 0 additions & 34 deletions src/Data/Bifunctor/Wrap.purs

This file was deleted.