File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,13 @@ module Data.Profunctor.Joker where
2
2
3
3
import Prelude
4
4
5
- import Data.Either (Either (..))
5
+ import Control.Alternative (empty )
6
+ import Control.MonadPlus (class MonadPlus )
7
+ import Data.Either (Either (..), either )
6
8
import Data.Newtype (class Newtype , un )
7
9
import Data.Profunctor (class Profunctor )
8
10
import Data.Profunctor.Choice (class Choice )
11
+ import Data.Profunctor.Cochoice (class Cochoice )
9
12
10
13
-- | Makes a trivial `Profunctor` for a covariant `Functor`.
11
14
newtype Joker f a b = Joker (f b )
@@ -38,5 +41,10 @@ instance bindJoker :: Bind f => Bind (Joker f a) where
38
41
39
42
instance monadJoker :: Monad m => Monad (Joker m a )
40
43
44
+ instance cochoiceJoker :: MonadPlus f => Cochoice (Joker f )
45
+ where
46
+ unleft (Joker fa) = Joker $ fa >>= either pure (const empty)
47
+ unright (Joker fb) = Joker $ fb >>= either (const empty) pure
48
+
41
49
hoistJoker :: forall f g a b . (f ~> g ) -> Joker f a b -> Joker g a b
42
50
hoistJoker f (Joker a) = Joker (f a)
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import Data.Newtype (class Newtype)
15
15
import Data.Profunctor (class Profunctor )
16
16
import Data.Profunctor.Choice (class Choice )
17
17
import Data.Profunctor.Closed (class Closed )
18
+ import Data.Profunctor.Cochoice (class Cochoice )
18
19
import Data.Profunctor.Strong (class Strong )
19
20
import Data.Tuple (Tuple (..))
20
21
@@ -75,6 +76,10 @@ instance choiceStar :: Applicative f => Choice (Star f) where
75
76
left (Star f) = Star $ either (map Left <<< f) (pure <<< Right )
76
77
right (Star f) = Star $ either (pure <<< Left ) (map Right <<< f)
77
78
79
+ instance cochoiceStar :: MonadPlus f => Cochoice (Star f ) where
80
+ unleft (Star f) = Star $ \a -> (=<<) (either pure (const empty)) $ f (Left a)
81
+ unright (Star f) = Star $ \a -> (=<<) (either (const empty) pure) $ f (Right a)
82
+
78
83
instance closedStar :: Distributive f => Closed (Star f ) where
79
84
closed (Star f) = Star \g -> distribute (f <<< g)
80
85
You can’t perform that action at this time.
0 commit comments