Skip to content
This repository was archived by the owner on Jun 6, 2018. It is now read-only.

Commit b2111fb

Browse files
committed
Docs
1 parent af7ef84 commit b2111fb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,50 @@
22

33
## Module Data.Functor.Coproduct
44

5+
6+
Functor coproducts
7+
58
#### `Coproduct`
69

710
``` purescript
811
newtype Coproduct f g a
912
= Coproduct (Either (f a) (g a))
1013
```
1114

15+
`Coproduct f g` is the coproduct of two functors `f` and `g`
1216

1317
#### `runCoproduct`
1418

1519
``` purescript
1620
runCoproduct :: forall f g a. Coproduct f g a -> Either (f a) (g a)
1721
```
1822

23+
Unwrap a coproduct
1924

2025
#### `left`
2126

2227
``` purescript
2328
left :: forall f g a. f a -> Coproduct f g a
2429
```
2530

31+
Left injection
2632

2733
#### `right`
2834

2935
``` purescript
3036
right :: forall f g a. g a -> Coproduct f g a
3137
```
3238

39+
Right injection
3340

3441
#### `coproduct`
3542

3643
``` purescript
3744
coproduct :: forall f g a b. (f a -> b) -> (g a -> b) -> Coproduct f g a -> b
3845
```
3946

47+
Eliminate a coproduct by providing eliminators for the left and
48+
right components
4049

4150
#### `functorCoproduct`
4251

src/Data/Functor/Coproduct.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
-- | Functor coproducts
2+
13
module Data.Functor.Coproduct where
24

35
import Data.Either
46
import Data.Foldable
57
import Data.Traversable
68

9+
-- | `Coproduct f g` is the coproduct of two functors `f` and `g`
710
newtype Coproduct f g a = Coproduct (Either (f a) (g a))
811

12+
-- | Unwrap a coproduct
913
runCoproduct :: forall f g a. Coproduct f g a -> Either (f a) (g a)
1014
runCoproduct (Coproduct x) = x
1115

16+
-- | Left injection
1217
left :: forall f g a. f a -> Coproduct f g a
1318
left = Coproduct <<< Left
1419

20+
-- | Right injection
1521
right :: forall f g a. g a -> Coproduct f g a
1622
right = Coproduct <<< Right
1723

24+
-- | Eliminate a coproduct by providing eliminators for the left and
25+
-- | right components
1826
coproduct :: forall f g a b. (f a -> b) -> (g a -> b) -> Coproduct f g a -> b
1927
coproduct f g = either f g <<< runCoproduct
2028

0 commit comments

Comments
 (0)