| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Yaml.YamlLight.Lens
Description
Lenses for working with YAML structures.
Synopsis
Traversals
nth :: Int -> Traversal' YamlLight YamlLight Source #
Lens into a sequence.
>>>YSeq [YStr "a", YStr "b", YStr "c"] ^? nth 1Just (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 StringJust "c"
key :: ByteString -> Traversal' YamlLight YamlLight Source #
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 +~ 1YMap (fromList [(YStr "name",YStr "Tony Stark"),(YStr "sequels",YStr "3")])
key' :: YamlLight -> Traversal' YamlLight YamlLight Source #
Lens into a mapping using a complex key.
Yaml parsing prism
_Yaml :: AsYaml a => Prism' YamlLight a Source #
Convert between YAML values and corresponding common Haskell values.
>>>YStr "-2.3" ^? _Yaml :: Maybe DoubleJust (-2.3)
>>>YStr "7b.3" ^? _Yaml :: Maybe DoubleNothing
>>>YStr "-23" ^? _Yaml :: Maybe IntJust (-23)
>>>YStr "Help, I'm trapped in a haddock factory!" ^? _Yaml :: Maybe StringJust "Help, I'm trapped in a haddock factory!"
>>>YStr "An integer" ^? _Yaml :: Maybe IntegerNothing
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]
Convert between YAML values and common types of Haskell values.
Numeric parsers
yamlReal :: Fractional b => YamlLight -> Maybe b Source #
Try to parse a Fractional value from a YamlLight.