yaml-light-lens-0.3.3.5: Lens interface to yaml-light.

Data.Yaml.YamlLight.Lens

Description

Lenses for working with YAML structures.

Synopsis

# Traversals

Lens into a sequence.

>>> YSeq [YStr "a", YStr "b", YStr "c"] ^? nth 1
Just (YStr "b")

>>> YSeq [YStr "a", YStr "b", YStr "c"] & nth 1 .~ YStr "B"
YSeq [YStr "a",YStr "B",YStr "c"]

>>> YSeq [YStr "a", YStr "b", YStr "c"] ^? nth 2 . _Yaml :: Maybe String
Just "c"


Lens into a mapping. ByteStrings are used as keys directly. If you wish to use a complex mapping key, see key'.

>>> let m = YMap $Map.fromList [(YStr "name", YStr "Tony Stark"), (YStr "sequels", YStr "2")] >>> m & key "sequels" . _Yaml +~ 1 YMap (fromList [(YStr "name",YStr "Tony Stark"),(YStr "sequels",YStr "3")])  Lens into a mapping using a complex key. # Yaml parsing prism Convert between YAML values and corresponding common Haskell values. >>> YStr "-2.3" ^? _Yaml :: Maybe Double Just (-2.3)  >>> YStr "7b.3" ^? _Yaml :: Maybe Double Nothing  >>> YStr "-23" ^? _Yaml :: Maybe Int Just (-23)  >>> YStr "Help, I'm trapped in a haddock factory!" ^? _Yaml :: Maybe String Just "Help, I'm trapped in a haddock factory!"  >>> YStr "An integer" ^? _Yaml :: Maybe Integer Nothing  If we just want to pull out those values that were successfully parsed, >>> let nums = YSeq [YStr "3", YStr "2a", YStr "1"] >>> nums ^.. each._Yaml :: [Int] [3,1]  Alternately, we may want to fail the entire parse if any element fails to parse. >>> sequenceA$ map (preview _Yaml) (nums ^.. each) :: Maybe [Int]
Nothing
>>> let nums' = YSeq [YStr "3", YStr "2", YStr "1"]
>>> sequenceA \$ map (preview _Yaml) (nums' ^.. each) :: Maybe [Int]
Just [3,2,1]


class AsYaml a where Source #

Convert between YAML values and common types of Haskell values.

Minimal complete definition

Methods

toYaml :: a -> YamlLight Source #

Instances
 Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens Methods Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens Methods Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens Methods Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens Methods Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens Methods Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens Methods Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens MethodstoYaml :: [YamlLight] -> YamlLight Source # Source # Instance detailsDefined in Data.Yaml.YamlLight.Lens Methods

# Numeric parsers

yamlInt :: Integral b => YamlLight -> Maybe b Source #

Try to parse an Integral value from a YamlLight.

Try to parse a Fractional value from a YamlLight.

# Orphan instances

 Source # Instance details Methods Source # Instance details Methods Source # Instance details Methods Source # Instance details Methods