module Data.Extensible.Match (
matchWith
, Match(..)
, _Match
, match
, mapMatch
, caseOf) where
import Data.Extensible.Internal.Rig
import Data.Extensible.Class
import Data.Extensible.Product
import Data.Extensible.Sum
import Data.Profunctor
import Data.Typeable
matchWith :: (forall x. f x -> g x -> r) -> f :* xs -> g :| xs -> r
matchWith f p = \(EmbedAt i h) -> views (pieceAt i) f p h
mapMatch :: (a -> b) -> Match h a x -> Match h b x
mapMatch f (Match g) = Match (f . g)
match :: Match h a :* xs -> h :| xs -> a
match = matchWith runMatch
caseOf :: h :| xs -> Match h a :* xs -> a
caseOf = flip match
infix 0 `caseOf`
newtype Match h a x = Match { runMatch :: h x -> a } deriving Typeable
_Match :: (Profunctor p, Functor f) => p (g x -> a) (f (h y -> b)) -> p (Match g a x) (f (Match h b y))
_Match = dimap runMatch (fmap Match)