{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeOperators #-}
module Composite.Record.Tuple (
singleton
, pattern (:|:)
, toFst
, toSnd
, fmapToFst
, fmapToSnd
, traverseToFst
, traverseToSnd
, fanout
, fanoutM
) where
import Composite.Record
singleton :: a -> Record (s :-> a : '[])
singleton a = a :*: RNil
pattern (:|:) :: a -> b -> Record (s :-> a : s' :-> b : '[])
pattern a :|: b = a :*: b :*: RNil
toFst :: (a -> b) -> a -> Record (s :-> b : s' :-> a : '[])
toFst f x = f x :*: x :*: RNil
toSnd :: (a -> b) -> a -> Record (s :-> a : s' :-> b : '[])
toSnd f x = x :*: f x :*: RNil
fmapToFst :: Functor f => (a -> b) -> f a -> f (Record (s :-> b : s' :-> a : '[]))
fmapToFst = fmap . toFst
fmapToSnd :: Functor f => (a -> b) -> f a -> f (Record (s :-> a : s' :-> b : '[]))
fmapToSnd = fmap . toSnd
traverseToFst :: Functor m => (a -> m b) -> a -> m (Record (s :-> b : s' :-> a : '[]))
traverseToFst f x = (:*: x :*: RNil) <$> f x
traverseToSnd :: Functor m => (a -> m b) -> a -> m (Record (s :-> a : s' :-> b : '[]))
traverseToSnd f x = (\y -> x :*: y :*: RNil) <$> f x
fanout :: (x -> a) -> (x -> b) -> x -> Record (s :-> a : s' :-> b : '[])
fanout f g x = f x :*: g x :*: RNil
fanoutM :: Applicative m => (x -> m a) -> (x -> m b) -> x -> m (Record (s :-> a : s' :-> b : '[]))
fanoutM f g x = (\y z -> y :*: z :*: RNil) <$> f x <*> g x