Skip to content

Commit

Permalink
splitStrong/Choice with Semigroupoid instead of Category constrain (#48)
Browse files Browse the repository at this point in the history
* splitStrong/Choice with Semigroupoing not a Category

* changelog
  • Loading branch information
erykciepiela authored Mar 7, 2024
1 parent 0a966a1 commit fd419d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
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 &&&

0 comments on commit fd419d8

Please sign in to comment.