Skip to content

splitStrong/Choice with Semigroupoid instead of Category constrain #48

New issue

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

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

Already on GitHub? Sign in to your account

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Breaking changes:
New features:

Bugfixes:
- `splitStrong` and `splitChoice` functions as not requiring `identity` have now relaxed constrain of `Semigroupoid` instead of `Catergory`.

Other improvements:

Expand Down
11 changes: 4 additions & 7 deletions src/Data/Profunctor/Choice.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Data.Profunctor.Choice where
import Prelude

import Data.Either (Either(..), either)
import Data.Profunctor (class Profunctor, dimap)
import Data.Profunctor (class Profunctor, rmap)

-- | The `Choice` class extends `Profunctor` with combinators for working with
-- | sum types.
Expand Down Expand Up @@ -46,7 +46,7 @@ instance choiceFn :: Choice (->) where
-- | `bi-map` would do for the `bi-functor` instance of `Either`.
splitChoice
:: forall p a b c d
. Category p
. Semigroupoid p
=> Choice p
=> p a b
-> p c d
Expand All @@ -73,14 +73,11 @@ infixr 2 splitChoice as +++
-- | function which will run the approriate computation based on the parameter supplied in the `Either` value.
fanin
:: forall p a b c
. Category p
. Semigroupoid p
=> Choice p
=> p a c
-> p b c
-> p (Either a b) c
fanin l r = (l +++ r) >>> join
where
join :: p (Either c c) c
join = dimap (either identity identity) identity identity
fanin l r = rmap (either identity identity) (l +++ r)

infixr 2 fanin as |||
11 changes: 4 additions & 7 deletions src/Data/Profunctor/Strong.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Data.Profunctor.Strong where

import Prelude

import Data.Profunctor (class Profunctor, dimap)
import Data.Profunctor (class Profunctor, lcmap)
import Data.Tuple (Tuple(..))

-- | The `Strong` class extends `Profunctor` with combinators for working with
Expand Down Expand Up @@ -45,7 +45,7 @@ instance strongFn :: Strong (->) where
-- | would do for the `bi-functor` instance of `Tuple`.
splitStrong
:: forall p a b c d
. Category p
. Semigroupoid p
=> Strong p
=> p a b
-> p c d
Expand All @@ -70,14 +70,11 @@ infixr 3 splitStrong as ***
-- | on the same input and return both results in a `Tuple`.
fanout
:: forall p a b c
. Category p
. Semigroupoid p
=> Strong p
=> p a b
-> p a c
-> p a (Tuple b c)
fanout l r = split >>> (l *** r)
where
split :: p a (Tuple a a)
split = dimap identity (\a -> Tuple a a) identity
fanout l r = lcmap (\a -> Tuple a a) (l *** r)

infixr 3 fanout as &&&