{-# OPTIONS_HADDOCK not-home #-}
module Optics.Internal.Utils where
import Data.Coerce
import qualified Data.Semigroup as SG
data Context a b t = Context (b -> t) a
deriving Functor
(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)
(#.) _f = coerce
infixl 8 .#
{-# INLINE (#.) #-}
(.#) :: Coercible a b => (b -> c) -> (a -> b) -> (a -> c)
(.#) f _g = coerce f
infixr 9 #.
{-# INLINE (.#) #-}
newtype Traversed f a = Traversed (f a)
runTraversed :: Functor f => Traversed f a -> f ()
runTraversed (Traversed fa) = () <$ fa
{-# INLINE runTraversed #-}
instance Applicative f => SG.Semigroup (Traversed f a) where
Traversed ma <> Traversed mb = Traversed (ma *> mb)
{-# INLINE (<>) #-}
instance Applicative f => Monoid (Traversed f a) where
mempty = Traversed (pure (error "Traversed: value used"))
mappend = (SG.<>)
{-# INLINE mempty #-}
{-# INLINE mappend #-}
data OrT f a = OrT !Bool (f a)
deriving Functor
instance Applicative f => Applicative (OrT f) where
pure = OrT False . pure
OrT a f <*> OrT b x = OrT (a || b) (f <*> x)
{-# INLINE pure #-}
{-# INLINE (<*>) #-}
wrapOrT :: f a -> OrT f a
wrapOrT = OrT True
{-# INLINE wrapOrT #-}