Skip to content

Commit 9b3d014

Browse files
authored
Merge pull request #30 from masaeedu/jokerchoice
Add instances for Joker
2 parents 1de584b + be868fc commit 9b3d014

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Data/Profunctor/Joker.purs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ module Data.Profunctor.Joker where
22

33
import Prelude
44

5+
import Data.Either (Either(..))
6+
import Data.Newtype (class Newtype, un)
57
import Data.Profunctor (class Profunctor)
6-
import Data.Newtype (class Newtype)
8+
import Data.Profunctor.Choice (class Choice)
79

810
-- | Makes a trivial `Profunctor` for a covariant `Functor`.
911
newtype Joker f a b = Joker (f b)
@@ -21,5 +23,20 @@ instance functorJoker :: Functor f => Functor (Joker f a) where
2123
instance profunctorJoker :: Functor f => Profunctor (Joker f) where
2224
dimap f g (Joker a) = Joker (map g a)
2325

26+
instance clownJoker :: Functor f => Choice (Joker f) where
27+
left (Joker f) = Joker $ map Left f
28+
right (Joker f) = Joker $ map Right f
29+
30+
instance applyJoker :: Apply f => Apply (Joker f a) where
31+
apply (Joker f) (Joker g) = Joker $ apply f g
32+
33+
instance applicativeJoker :: Applicative f => Applicative (Joker f a) where
34+
pure = Joker <<< pure
35+
36+
instance bindJoker :: Bind f => Bind (Joker f a) where
37+
bind (Joker ma) amb = Joker $ ma >>= (amb >>> un Joker)
38+
39+
instance monadJoker :: Monad m => Monad (Joker m a)
40+
2441
hoistJoker :: forall f g a b. (f ~> g) -> Joker f a b -> Joker g a b
2542
hoistJoker f (Joker a) = Joker (f a)

0 commit comments

Comments
 (0)