File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 2525 "purescript-contravariant" : " ^3.0.0" ,
2626 "purescript-distributive" : " ^3.0.0" ,
2727 "purescript-either" : " ^3.0.0" ,
28+ "purescript-exists" : " ^3.0.0" ,
2829 "purescript-tuples" : " ^4.0.0"
2930 }
3031}
Original file line number Diff line number Diff line change 1+ module Data.Profunctor.Split where
2+
3+ import Prelude
4+
5+ import Data.Exists (Exists , mkExists , runExists )
6+ import Data.Functor.Invariant (class Invariant , imap )
7+ import Data.Profunctor (class Profunctor )
8+
9+ newtype Split f a b = Split (Exists (SplitF f a b ))
10+
11+ data SplitF f a b x = SplitF (a -> x ) (x -> b ) (f x )
12+
13+ instance profunctorSplit :: Profunctor (Split f ) where
14+ dimap f g = unSplit \h i -> split (h <<< f) (g <<< i)
15+
16+ split :: forall f a b x . (a -> x ) -> (x -> b ) -> f x -> Split f a b
17+ split f g fx = Split (mkExists (SplitF f g fx))
18+
19+ unSplit :: forall f a b r . (forall x . (a -> x ) -> (x -> b ) -> f x -> r ) -> Split f a b -> r
20+ unSplit f (Split e) = runExists (\(SplitF g h fx) -> f g h fx) e
21+
22+ liftSplit :: forall f a . f a -> Split f a a
23+ liftSplit = split id id
24+
25+ lowerSplit :: forall f a . Invariant f => Split f a a -> f a
26+ lowerSplit = unSplit (flip imap)
27+
28+ hoistSplit :: forall f g a b . (f ~> g ) -> Split f a b -> Split g a b
29+ hoistSplit nat = unSplit (\f g -> split f g <<< nat)
You can’t perform that action at this time.
0 commit comments