{-# LANGUAGE DataKinds #-}
module Optics.IxSetter
(
IxSetter
, IxSetter'
, isets
, iover
, imapped
, iset
, iset'
, iover'
, A_Setter
, FunctorWithIndex(..)
) where
import Data.Profunctor.Indexed
import Optics.Internal.Indexed
import Optics.Internal.Indexed.Classes
import Optics.Internal.IxSetter
import Optics.Internal.Optic
import Optics.Internal.Utils
type IxSetter i s t a b = Optic A_Setter (WithIx i) s t a b
type IxSetter' i s a = Optic' A_Setter (WithIx i) s a
iover
:: (Is k A_Setter, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> a -> b) -> s -> t
iover o = \f -> runIxFunArrow (getOptic (castOptic @A_Setter o) (IxFunArrow f)) id
{-# INLINE iover #-}
iover'
:: (Is k A_Setter, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> a -> b) -> s -> t
iover' o = \f ->
let star = getOptic (castOptic @A_Setter o) $ IxStar (\i -> wrapIdentity' . f i)
in unwrapIdentity' . runIxStar star id
{-# INLINE iover' #-}
iset
:: (Is k A_Setter, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> b) -> s -> t
iset o = \f -> iover o (\i _ -> f i)
{-# INLINE iset #-}
iset'
:: (Is k A_Setter, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> b) -> s -> t
iset' o = \f -> iover' o (\i _ -> f i)
{-# INLINE iset' #-}
isets
:: ((i -> a -> b) -> s -> t)
-> IxSetter i s t a b
isets f = Optic (iroam f)
{-# INLINE isets #-}
imapped :: FunctorWithIndex i f => IxSetter i (f a) (f b) a b
imapped = Optic imapped__
{-# INLINE imapped #-}