{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Profunctor.Optic.Operator (
(&)
, (%)
, (#)
, (^.)
, (^%)
, (#^)
, (..~)
, (.~)
, (%%~)
, (%~)
, (##~)
, (#~)
) where
import Data.Function
import Data.Profunctor.Optic.Carrier
import Data.Profunctor.Optic.Types
import Data.Profunctor.Optic.Import
import Data.Profunctor.Optic.Index
import qualified Data.Bifunctor as B
infixr 4 .~, ..~, %~, %%~, #~, ##~
infixl 8 ^., ^%
infixr 8 #^
(^.) :: s -> AView s a -> a
(^.) s o = withPrimView o id s
{-# INLINE ( ^. ) #-}
(^%) :: (Additive-Monoid) i => s -> AIxview i s a -> (Maybe i, a)
(^%) s o = withPrimView o (B.first Just) . (zero,) $ s
{-# INLINE (^%) #-}
(#^) :: AReview t b -> b -> t
o #^ b = withPrimReview o id b
{-# INLINE (#^) #-}
(..~) :: Optic (->) s t a b -> (a -> b) -> s -> t
(..~) = id
{-# INLINE (..~) #-}
(.~) :: Optic (->) s t a b -> b -> s -> t
(.~) o b = o (const b)
{-# INLINE (.~) #-}
(%%~) :: (Additive-Monoid) i => AIxsetter i s t a b -> (i -> a -> b) -> s -> t
(%%~) o f = withIxsetter o f zero
{-# INLINE (%%~) #-}
(%~) :: (Additive-Monoid) i => AIxsetter i s t a b -> (i -> b) -> s -> t
(%~) o = (%%~) o . (const .)
{-# INLINE (%~) #-}
(##~) :: (Additive-Monoid) k => ACxsetter k s t a b -> (k -> a -> b) -> s -> t
(##~) o f = withCxsetter o f zero
{-# INLINE (##~) #-}
(#~) :: (Additive-Monoid) k => ACxsetter k s t a b -> (k -> b) -> s -> t
(#~) o kb = o ##~ flip (const kb)
{-# INLINE (#~) #-}