This repository was archived by the owner on Jun 6, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 22
33## Module Data.Functor.Coproduct
44
5+
6+ Functor coproducts
7+
58#### ` Coproduct `
69
710``` purescript
811newtype 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
1620runCoproduct :: 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
2328left :: forall f g a. f a -> Coproduct f g a
2429```
2530
31+ Left injection
2632
2733#### ` right `
2834
2935``` purescript
3036right :: forall f g a. g a -> Coproduct f g a
3137```
3238
39+ Right injection
3340
3441#### ` coproduct `
3542
3643``` purescript
3744coproduct :: 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
Original file line number Diff line number Diff line change 1+ -- | Functor coproducts
2+
13module Data.Functor.Coproduct where
24
35import Data.Either
46import Data.Foldable
57import Data.Traversable
68
9+ -- | `Coproduct f g` is the coproduct of two functors `f` and `g`
710newtype Coproduct f g a = Coproduct (Either (f a ) (g a ))
811
12+ -- | Unwrap a coproduct
913runCoproduct :: forall f g a . Coproduct f g a -> Either (f a ) (g a )
1014runCoproduct (Coproduct x) = x
1115
16+ -- | Left injection
1217left :: forall f g a . f a -> Coproduct f g a
1318left = Coproduct <<< Left
1419
20+ -- | Right injection
1521right :: forall f g a . g a -> Coproduct f g a
1622right = Coproduct <<< Right
1723
24+ -- | Eliminate a coproduct by providing eliminators for the left and
25+ -- | right components
1826coproduct :: forall f g a b . (f a -> b ) -> (g a -> b ) -> Coproduct f g a -> b
1927coproduct f g = either f g <<< runCoproduct
2028
You can’t perform that action at this time.
0 commit comments