module Optics.Setter
(
Setter
, Setter'
, sets
, over
, mapped
, set
, set'
, over'
, rewriteOf
, transformOf
, 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 :: forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
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
f -> forall (i :: OpticKind) (a :: OpticKind) (b :: OpticKind).
FunArrow i a b -> a -> b
runFunArrow forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (p :: OpticKind -> OpticKind -> OpticKind -> OpticKind)
(k :: OpticKind) (is :: IxList) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind) (i :: OpticKind).
Profunctor p =>
Optic k is s t a b -> Optic_ k p i (Curry is i) s t a b
getOptic (forall (destKind :: OpticKind) (srcKind :: OpticKind)
(is :: IxList) (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
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) (forall (i :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(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' :: forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
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
f ->
let star :: Star Identity' (Curry is Any) s t
star = forall (p :: OpticKind -> OpticKind -> OpticKind -> OpticKind)
(k :: OpticKind) (is :: IxList) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind) (i :: OpticKind).
Profunctor p =>
Optic k is s t a b -> Optic_ k p i (Curry is i) s t a b
getOptic (forall (destKind :: OpticKind) (srcKind :: OpticKind)
(is :: IxList) (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
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) forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (f :: OpticKind -> OpticKind) (i :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
(a -> f b) -> Star f i a b
Star (forall (a :: OpticKind). a -> Identity' a
wrapIdentity' forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. a -> b
f)
in forall (a :: OpticKind). Identity' a -> a
unwrapIdentity' forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (f :: OpticKind -> OpticKind) (i :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
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 :: forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set Optic k is s t a b
o = forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over Optic k is s t a b
o forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const
{-# INLINE set #-}
set'
:: Is k A_Setter
=> Optic k is s t a b
-> b -> s -> t
set' :: forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
set' Optic k is s t a b
o = forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over' Optic k is s t a b
o forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const
{-# INLINE set' #-}
sets
:: ((a -> b) -> s -> t)
-> Setter s t a b
sets :: forall (a :: OpticKind) (b :: OpticKind) (s :: OpticKind)
(t :: OpticKind).
((a -> b) -> s -> t) -> Setter s t a b
sets (a -> b) -> s -> t
f = forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(forall (p :: OpticKind -> OpticKind -> OpticKind -> OpticKind)
(i :: OpticKind).
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic (forall (p :: OpticKind -> OpticKind -> OpticKind -> OpticKind)
(a :: OpticKind) (b :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(i :: OpticKind).
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 :: forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
(b :: OpticKind).
Functor f =>
Setter (f a) (f b) a b
mapped = forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(forall (p :: OpticKind -> OpticKind -> OpticKind -> OpticKind)
(i :: OpticKind).
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic forall (p :: OpticKind -> OpticKind -> OpticKind -> OpticKind)
(f :: OpticKind -> OpticKind) (i :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(Mapping p, Functor f) =>
Optic__ p i i (f a) (f b) a b
mapped__
{-# INLINE mapped #-}
rewriteOf :: Is k A_Setter => Optic k is a b a b -> (b -> Maybe a) -> a -> b
rewriteOf :: forall (k :: OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
Is k A_Setter =>
Optic k is a b a b -> (b -> Maybe a) -> a -> b
rewriteOf Optic k is a b a b
o b -> Maybe a
f = a -> b
go
where
go :: a -> b
go = forall (k :: OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
Is k A_Setter =>
Optic k is a b a b -> (b -> b) -> a -> b
transformOf Optic k is a b a b
o forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \b
x -> forall (b :: OpticKind) (a :: OpticKind).
b -> (a -> b) -> Maybe a -> b
maybe b
x a -> b
go (b -> Maybe a
f b
x)
{-# INLINE rewriteOf #-}
transformOf :: Is k A_Setter => Optic k is a b a b -> (b -> b) -> a -> b
transformOf :: forall (k :: OpticKind) (is :: IxList) (a :: OpticKind)
(b :: OpticKind).
Is k A_Setter =>
Optic k is a b a b -> (b -> b) -> a -> b
transformOf Optic k is a b a b
o b -> b
f = a -> b
go
where
go :: a -> b
go = b -> b
f forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
over Optic k is a b a b
o a -> b
go
{-# INLINE transformOf #-}