File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## Module Data.Profunctor.Star
2
+
3
+ #### ` Star `
4
+
5
+ ``` purescript
6
+ newtype Star f a b
7
+ = Star (a -> f b)
8
+ ```
9
+
10
+ ` Star ` turns a ` Functor ` into a ` Profunctor ` .
11
+
12
+ ##### Instances
13
+ ``` purescript
14
+ instance profunctorStar :: (Functor f) => Profunctor (Star f)
15
+ instance strongStar :: (Functor f) => Strong (Star f)
16
+ instance choiceStar :: (Applicative f) => Choice (Star f)
17
+ ```
18
+
19
+ #### ` runStar `
20
+
21
+ ``` purescript
22
+ runStar :: forall f a b. Star f a b -> a -> f b
23
+ ```
24
+
25
+ Unwrap a value of type ` Star f a b ` .
26
+
27
+
Original file line number Diff line number Diff line change
1
+ module Data.Profunctor.Star where
2
+
3
+ import Prelude
4
+
5
+ import Data.Tuple
6
+ import Data.Either
7
+ import Data.Profunctor
8
+ import Data.Profunctor.Strong
9
+ import Data.Profunctor.Choice
10
+
11
+ -- | `Star` turns a `Functor` into a `Profunctor`.
12
+ newtype Star f a b = Star (a -> f b )
13
+
14
+ -- | Unwrap a value of type `Star f a b`.
15
+ runStar :: forall f a b . Star f a b -> a -> f b
16
+ runStar (Star f) = f
17
+
18
+ instance profunctorStar :: (Functor f ) => Profunctor (Star f ) where
19
+ dimap f g (Star ft) = Star (f >>> ft >>> map g)
20
+
21
+ instance strongStar :: (Functor f ) => Strong (Star f ) where
22
+ first (Star f) = Star \(Tuple s x) -> map (`Tuple ` x) (f s)
23
+ second (Star f) = Star \(Tuple x s) -> map (Tuple x) (f s)
24
+
25
+ instance choiceStar :: (Applicative f ) => Choice (Star f ) where
26
+ left (Star f) = Star $ either (map Left <<< f) (pure <<< Right )
27
+ right (Star f) = Star $ either (pure <<< Left ) (map Right <<< f)
You can’t perform that action at this time.
0 commit comments