{-# 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 :: Optic k is s t a b -> (i -> a -> b) -> s -> t
iover Optic k is s t a b
o = \i -> a -> b
f -> IxFunArrow (i -> i) s t -> (i -> i) -> s -> t
forall i a b. IxFunArrow i a b -> i -> a -> b
runIxFunArrow (Optic A_Setter is s t a b
-> Optic__ IxFunArrow i (Curry is i) s t a b
forall (p :: * -> * -> * -> *) k (is :: IxList) s t a b i.
Profunctor p =>
Optic k is s t a b -> Optic_ k p i (Curry is i) s t a b
getOptic (Optic k is s t a b -> Optic A_Setter is s t a b
forall destKind srcKind (is :: IxList) s t a b.
Is srcKind destKind =>
Optic srcKind is s t a b -> Optic destKind is s t a b
castOptic @A_Setter Optic k is s t a b
o) ((i -> a -> b) -> IxFunArrow i a b
forall i a b. (i -> a -> b) -> IxFunArrow i a b
IxFunArrow i -> a -> b
f)) i -> i
forall a. a -> a
id
{-# INLINE iover #-}
iover'
:: (Is k A_Setter, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> a -> b) -> s -> t
iover' :: Optic k is s t a b -> (i -> a -> b) -> s -> t
iover' Optic k is s t a b
o = \i -> a -> b
f ->
let star :: IxStar Identity' (Curry is i) s t
star = Optic A_Setter is s t a b
-> Optic_ A_Setter (IxStar Identity') i (Curry is i) s t a b
forall (p :: * -> * -> * -> *) k (is :: IxList) s t a b i.
Profunctor p =>
Optic k is s t a b -> Optic_ k p i (Curry is i) s t a b
getOptic (Optic k is s t a b -> Optic A_Setter is s t a b
forall destKind srcKind (is :: IxList) s t a b.
Is srcKind destKind =>
Optic srcKind is s t a b -> Optic destKind is s t a b
castOptic @A_Setter Optic k is s t a b
o) Optic__ (IxStar Identity') i (Curry is i) s t a b
-> Optic__ (IxStar Identity') i (Curry is i) s t a b
forall a b. (a -> b) -> a -> b
$ (i -> a -> Identity' b) -> IxStar Identity' i a b
forall (f :: * -> *) i a b. (i -> a -> f b) -> IxStar f i a b
IxStar (\i
i -> b -> Identity' b
forall a. a -> Identity' a
wrapIdentity' (b -> Identity' b) -> (a -> b) -> a -> Identity' b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> a -> b
f i
i)
in Identity' t -> t
forall a. Identity' a -> a
unwrapIdentity' (Identity' t -> t) -> (s -> Identity' t) -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IxStar Identity' (i -> i) s t -> (i -> i) -> s -> Identity' t
forall (f :: * -> *) i a b. IxStar f i a b -> i -> a -> f b
runIxStar IxStar Identity' (Curry is i) s t
IxStar Identity' (i -> i) s t
star i -> i
forall a. a -> a
id
{-# INLINE iover' #-}
iset
:: (Is k A_Setter, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> b) -> s -> t
iset :: Optic k is s t a b -> (i -> b) -> s -> t
iset Optic k is s t a b
o = \i -> b
f -> Optic k is s t a b -> (i -> a -> b) -> s -> t
forall k (is :: IxList) i s t a b.
(Is k A_Setter, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> b) -> s -> t
iover Optic k is s t a b
o (\i
i a
_ -> i -> b
f i
i)
{-# INLINE iset #-}
iset'
:: (Is k A_Setter, is `HasSingleIndex` i)
=> Optic k is s t a b
-> (i -> b) -> s -> t
iset' :: Optic k is s t a b -> (i -> b) -> s -> t
iset' Optic k is s t a b
o = \i -> b
f -> Optic k is s t a b -> (i -> a -> b) -> s -> t
forall k (is :: IxList) i s t a b.
(Is k A_Setter, HasSingleIndex is i) =>
Optic k is s t a b -> (i -> a -> b) -> s -> t
iover' Optic k is s t a b
o (\i
i a
_ -> i -> b
f i
i)
{-# INLINE iset' #-}
isets
:: ((i -> a -> b) -> s -> t)
-> IxSetter i s t a b
isets :: ((i -> a -> b) -> s -> t) -> IxSetter i s t a b
isets (i -> a -> b) -> s -> t
f = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Setter p i (Curry (WithIx i) i) s t a b)
-> IxSetter i s t a b
forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic (((i -> a -> b) -> s -> t) -> p i a b -> p (i -> i) s t
forall (p :: * -> * -> * -> *) i a b s t j.
Mapping p =>
((i -> a -> b) -> s -> t) -> p j a b -> p (i -> j) s t
iroam (i -> a -> b) -> s -> t
f)
{-# INLINE isets #-}
imapped :: FunctorWithIndex i f => IxSetter i (f a) (f b) a b
imapped :: IxSetter i (f a) (f b) a b
imapped = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Setter p i (Curry (WithIx i) i) (f a) (f b) a b)
-> IxSetter i (f a) (f b) a b
forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Setter p i (Curry (WithIx i) i) (f a) (f b) a b
forall (p :: * -> * -> * -> *) i (f :: * -> *) j a b.
(Mapping p, FunctorWithIndex i f) =>
Optic__ p j (i -> j) (f a) (f b) a b
imapped__
{-# INLINE imapped #-}