module Optics.Setter
(
Setter
, Setter'
, sets
, over
, mapped
, set
, set'
, over'
, A_Setter
) where
import Data.Profunctor.Indexed
import Optics.Internal.Optic
import Optics.Internal.Setter
import Optics.Internal.Utils
type Setter s t a b = Optic A_Setter NoIx s t a b
type Setter' s a = Optic' A_Setter NoIx s a
over
:: Is k A_Setter
=> Optic k is s t a b
-> (a -> b) -> s -> t
over :: Optic k is s t a b -> (a -> b) -> s -> t
over Optic k is s t a b
o = \a -> b
f -> FunArrow (Curry is Any) s t -> s -> t
forall i a b. FunArrow i a b -> a -> b
runFunArrow (FunArrow (Curry is Any) s t -> s -> t)
-> FunArrow (Curry is Any) s t -> s -> t
forall a b. (a -> b) -> a -> b
$ Optic A_Setter is s t a b
-> Optic__ FunArrow Any (Curry is Any) 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) ((a -> b) -> FunArrow Any a b
forall i a b. (a -> b) -> FunArrow i a b
FunArrow a -> b
f)
{-# INLINE over #-}
over'
:: Is k A_Setter
=> Optic k is s t a b
-> (a -> b) -> s -> t
over' :: Optic k is s t a b -> (a -> b) -> s -> t
over' Optic k is s t a b
o = \a -> b
f ->
let star :: Star Identity' (Curry is Any) s t
star = Optic A_Setter is s t a b
-> Optic_ A_Setter (Star Identity') Any (Curry is Any) 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__ (Star Identity') Any (Curry is Any) s t a b
-> Optic__ (Star Identity') Any (Curry is Any) s t a b
forall a b. (a -> b) -> a -> b
$ (a -> Identity' b) -> Star Identity' Any a b
forall (f :: * -> *) i a b. (a -> f b) -> Star f i a b
Star (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
. a -> b
f)
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
. Star Identity' (Curry is Any) s t -> s -> Identity' t
forall (f :: * -> *) i a b. Star f i a b -> a -> f b
runStar Star Identity' (Curry is Any) s t
star
{-# INLINE over' #-}
set
:: Is k A_Setter
=> Optic k is s t a b
-> b -> s -> t
set :: Optic k is s t a b -> b -> s -> t
set Optic k is s t a b
o = Optic k is s t a b -> (a -> b) -> s -> t
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over Optic k is s t a b
o ((a -> b) -> s -> t) -> (b -> a -> b) -> b -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a -> b
forall a b. a -> b -> a
const
{-# INLINE set #-}
set'
:: Is k A_Setter
=> Optic k is s t a b
-> b -> s -> t
set' :: Optic k is s t a b -> b -> s -> t
set' Optic k is s t a b
o = Optic k is s t a b -> (a -> b) -> s -> t
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over' Optic k is s t a b
o ((a -> b) -> s -> t) -> (b -> a -> b) -> b -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a -> b
forall a b. a -> b -> a
const
{-# INLINE set' #-}
sets
:: ((a -> b) -> s -> t)
-> Setter s t a b
sets :: ((a -> b) -> s -> t) -> Setter s t a b
sets (a -> b) -> s -> t
f = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Setter p i (Curry NoIx i) s t a b)
-> Setter 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 (((a -> b) -> s -> t) -> p i a b -> p i s t
forall (p :: * -> * -> * -> *) a b s t i.
Mapping p =>
((a -> b) -> s -> t) -> p i a b -> p i s t
roam (a -> b) -> s -> t
f)
{-# INLINE sets #-}
mapped :: Functor f => Setter (f a) (f b) a b
mapped :: Setter (f a) (f b) a b
mapped = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Setter p i (Curry NoIx i) (f a) (f b) a b)
-> Setter (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 NoIx i) (f a) (f b) a b
forall (p :: * -> * -> * -> *) (f :: * -> *) i a b.
(Mapping p, Functor f) =>
Optic__ p i i (f a) (f b) a b
mapped__
{-# INLINE mapped #-}