Skip to content

Add arrow combinators #4

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
merged 1 commit into from
Mar 6, 2015
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ instance choiceArr :: Choice Prim.Function
```


#### `(+++)`

``` purescript
(+++) :: forall p a b c d. (Category p, Choice p) => p a b -> p c d -> p (Either a c) (Either b d)
```


#### `(|||)`

``` purescript
(|||) :: forall p a b c. (Category p, Choice p) => p a c -> p b c -> p (Either a b) c
```



## Module Data.Profunctor.Strong

Expand All @@ -66,4 +80,18 @@ class (Profunctor p) <= Strong p where

``` purescript
instance strongArr :: Strong Prim.Function
```


#### `(***)`

``` purescript
(***) :: forall p a b c d. (Category p, Strong p) => p a b -> p c d -> p (Tuple a c) (Tuple b d)
```


#### `(&&&)`

``` purescript
(&&&) :: forall p a b c. (Category p, Strong p) => p a b -> p a c -> p a (Tuple b c)
```
16 changes: 14 additions & 2 deletions src/Data/Profunctor/Choice.purs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Data.Profunctor.Choice where

import Data.Either (Either(..))
import Data.Profunctor (Profunctor)
import Data.Either (Either(..), either)
import Data.Profunctor

class (Profunctor p) <= Choice p where
left :: forall a b c. p a b -> p (Either a c) (Either b c)
Expand All @@ -12,3 +12,15 @@ module Data.Profunctor.Choice where
left _ (Right c) = Right c

right = (<$>)

infixr 2 +++
infixr 2 |||

(+++) :: forall p a b c d. (Category p, Choice p) => p a b -> p c d -> p (Either a c) (Either b d)
(+++) l r = left l >>> right r

(|||) :: forall p a b c. (Category p, Choice p) => p a c -> p b c -> p (Either a b) c
(|||) l r = (l +++ r) >>> join
where
join :: p (Either c c) c
join = dimap (either id id) id id
15 changes: 14 additions & 1 deletion src/Data/Profunctor/Strong.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Data.Profunctor.Strong where

import Data.Profunctor (Profunctor)
import Data.Profunctor
import Data.Tuple (Tuple(..))

class (Profunctor p) <= Strong p where
Expand All @@ -10,3 +10,16 @@ module Data.Profunctor.Strong where
instance strongArr :: Strong (->) where
first a2b (Tuple a c) = Tuple (a2b a) c
second = (<$>)

infixr 3 ***
infixr 3 &&&

(***) :: forall p a b c d. (Category p, Strong p) => p a b -> p c d -> p (Tuple a c) (Tuple b d)
(***) l r = first l >>> second r

(&&&) :: forall p a b c. (Category p, Strong p) => p a b -> p a c -> p a (Tuple b c)
(&&&) l r = split >>> (l *** r)
where
split :: p a (Tuple a a)
split = dimap id (\a -> Tuple a a) id