Skip to content

Commit d2dee78

Browse files
committed
Merge pull request #4 from purescript/arrow-combinators
Add arrow combinators
2 parents 1265470 + c8c2ce2 commit d2dee78

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ instance choiceArr :: Choice Prim.Function
5050
```
5151

5252

53+
#### `(+++)`
54+
55+
``` purescript
56+
(+++) :: forall p a b c d. (Category p, Choice p) => p a b -> p c d -> p (Either a c) (Either b d)
57+
```
58+
59+
60+
#### `(|||)`
61+
62+
``` purescript
63+
(|||) :: forall p a b c. (Category p, Choice p) => p a c -> p b c -> p (Either a b) c
64+
```
65+
66+
5367

5468
## Module Data.Profunctor.Strong
5569

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

6781
``` purescript
6882
instance strongArr :: Strong Prim.Function
83+
```
84+
85+
86+
#### `(***)`
87+
88+
``` purescript
89+
(***) :: forall p a b c d. (Category p, Strong p) => p a b -> p c d -> p (Tuple a c) (Tuple b d)
90+
```
91+
92+
93+
#### `(&&&)`
94+
95+
``` purescript
96+
(&&&) :: forall p a b c. (Category p, Strong p) => p a b -> p a c -> p a (Tuple b c)
6997
```

src/Data/Profunctor/Choice.purs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Data.Profunctor.Choice where
22

3-
import Data.Either (Either(..))
4-
import Data.Profunctor (Profunctor)
3+
import Data.Either (Either(..), either)
4+
import Data.Profunctor
55

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

1414
right = (<$>)
15+
16+
infixr 2 +++
17+
infixr 2 |||
18+
19+
(+++) :: forall p a b c d. (Category p, Choice p) => p a b -> p c d -> p (Either a c) (Either b d)
20+
(+++) l r = left l >>> right r
21+
22+
(|||) :: forall p a b c. (Category p, Choice p) => p a c -> p b c -> p (Either a b) c
23+
(|||) l r = (l +++ r) >>> join
24+
where
25+
join :: p (Either c c) c
26+
join = dimap (either id id) id id

src/Data/Profunctor/Strong.purs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Data.Profunctor.Strong where
22

3-
import Data.Profunctor (Profunctor)
3+
import Data.Profunctor
44
import Data.Tuple (Tuple(..))
55

66
class (Profunctor p) <= Strong p where
@@ -10,3 +10,16 @@ module Data.Profunctor.Strong where
1010
instance strongArr :: Strong (->) where
1111
first a2b (Tuple a c) = Tuple (a2b a) c
1212
second = (<$>)
13+
14+
infixr 3 ***
15+
infixr 3 &&&
16+
17+
(***) :: forall p a b c d. (Category p, Strong p) => p a b -> p c d -> p (Tuple a c) (Tuple b d)
18+
(***) l r = first l >>> second r
19+
20+
(&&&) :: forall p a b c. (Category p, Strong p) => p a b -> p a c -> p a (Tuple b c)
21+
(&&&) l r = split >>> (l *** r)
22+
where
23+
split :: p a (Tuple a a)
24+
split = dimap id (\a -> Tuple a a) id
25+

0 commit comments

Comments
 (0)