module Config.Lens
( key
, text
, number
, atom
, list
, values
, sections
, ann
, valuePlate
) where
import Config.Value
import Data.Text
key ::
Applicative f =>
Text ->
(Value a -> f (Value a)) -> Value a -> f (Value a)
key i = sections . traverse . section i
section ::
Applicative f =>
Text ->
(Value a -> f (Value a)) -> Section a -> f (Section a)
section i f s@(Section a j v) | i == j = Section a j <$> f v
| otherwise = pure s
sections :: Applicative f => ([Section a] -> f [Section a]) -> Value a -> f (Value a)
sections f (Sections a xs) = Sections a <$> f xs
sections _ v = pure v
text :: Applicative f => (Text -> f Text) -> Value a -> f (Value a)
text f (Text a t) = Text a <$> f t
text _ v = pure v
atom :: Applicative f => (Atom -> f Atom) -> Value a -> f (Value a)
atom f (Atom a t) = Atom a <$> f t
atom _ v = pure v
number :: Applicative f => (Integer -> f Integer) -> Value a -> f (Value a)
number f (Number a b n) = Number a b <$> f n
number _ v = pure v
list :: Applicative f => ([Value a] -> f [Value a]) -> Value a -> f (Value a)
list f (List a xs) = List a <$> f xs
list _ v = pure v
valuePlate :: Applicative f => (Value a -> f (Value a)) -> Value a -> f (Value a)
valuePlate f (List a xs) = List a <$> traverse f xs
valuePlate f (Sections a xs) = Sections a <$> traverse (sectionVal f) xs
valuePlate _ v = pure v
sectionVal :: Functor f => (Value a -> f (Value a)) -> Section a -> f (Section a)
sectionVal f (Section a k v) = Section a k <$> f v
values :: Applicative f => (Value a -> f (Value a)) -> Value a -> f (Value a)
values = list . traverse
ann :: Functor f => (a -> f a) -> Value a -> f (Value a)
ann f v =
case v of
Sections a x -> (\a' -> Sections a' x ) <$> f a
Number a x y -> (\a' -> Number a' x y) <$> f a
Floating a x y -> (\a' -> Floating a' x y) <$> f a
Text a x -> (\a' -> Text a' x ) <$> f a
Atom a x -> (\a' -> Atom a' x ) <$> f a
List a x -> (\a' -> List a' x ) <$> f a