Skip to content

Commit 65810f5

Browse files
committed
Merge pull request #1 from joneshf/master
Added `Choice` and `Strong`.
2 parents 012b01a + 21f8212 commit 65810f5

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,32 @@
1717

1818
lmap :: forall a b c p. (Profunctor p) => (a -> b) -> p b c -> p a c
1919

20-
rmap :: forall a b c p. (Profunctor p) => (b -> c) -> p a b -> p a c
20+
rmap :: forall a b c p. (Profunctor p) => (b -> c) -> p a b -> p a c
21+
22+
23+
## Module Data.Profunctor.Choice
24+
25+
### Type Classes
26+
27+
class (Profunctor p) <= Choice p where
28+
left :: forall a b c. p a b -> p (Either a c) (Either b c)
29+
right :: forall a b c. p b c -> p (Either a b) (Either a c)
30+
31+
32+
### Type Class Instances
33+
34+
instance choiceArr :: Choice Prim.Function
35+
36+
37+
## Module Data.Profunctor.Strong
38+
39+
### Type Classes
40+
41+
class (Profunctor p) <= Strong p where
42+
first :: forall a b c. p a b -> p (Tuple a c) (Tuple b c)
43+
second :: forall a b c. p b c -> p (Tuple a b) (Tuple a c)
44+
45+
46+
### Type Class Instances
47+
48+
instance strongArr :: Strong Prim.Function

bower.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
"bower.json",
2020
"Gruntfile.js",
2121
"package.json"
22-
]
22+
],
23+
"dependencies": {
24+
"purescript-either": "~0.1.4",
25+
"purescript-tuples": "~0.2.2"
26+
}
2327
}

src/Data/Profunctor/Choice.purs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Data.Profunctor.Choice where
2+
3+
import Data.Either (Either(..))
4+
import Data.Profunctor (Profunctor)
5+
6+
class (Profunctor p) <= Choice p where
7+
left :: forall a b c. p a b -> p (Either a c) (Either b c)
8+
right :: forall a b c. p b c -> p (Either a b) (Either a c)
9+
10+
instance choiceArr :: Choice (->) where
11+
left a2b (Left a) = Left $ a2b a
12+
left _ (Right c) = Right c
13+
14+
right = (<$>)

src/Data/Profunctor/Strong.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Data.Profunctor.Strong where
2+
3+
import Data.Profunctor (Profunctor)
4+
import Data.Tuple (Tuple(..))
5+
6+
class (Profunctor p) <= Strong p where
7+
first :: forall a b c. p a b -> p (Tuple a c) (Tuple b c)
8+
second :: forall a b c. p b c -> p (Tuple a b) (Tuple a c)
9+
10+
instance strongArr :: Strong (->) where
11+
first a2b (Tuple a c) = Tuple (a2b a) c
12+
second = (<$>)

0 commit comments

Comments
 (0)