You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a yaml object which has been parsed successfully and I'm interested in just a couple of the keys. I'd like to be able to specify the paths for the keys and cast them to strings. Is there an easy way to do this? Couldn't see anything in the docs
The text was updated successfully, but these errors were encountered:
MoultingYAML doesn't provide that facility. Currently, the best way to achieve that is to define a function on the lines of the following:
defgetFromPath(yaml: YamlValue, path: List[String]):Option[String] = {
path match {
caseNil=> yaml match {
caseYamlString(s) =>Some(s)
case _ =>None
}
case h :: t => yaml match {
caseYamlObject(fields) => fields.get(YamlString(h)).flatMap(getFromPath(_, t))
case _ =>None
}
}
}
valyaml="""k1: k2: k3: "test" k3: "2"""".parseYaml
getFromPath(yaml, List("k1")) // returns None
getFromPath(yaml, List("k1", "k2", "k3")) // returns Some("test")
getFromPath(yaml, List("k1", "k3")) // returns Some("2")
However, I have on my backlog the idea to integrate a lens library (probably Monocle) with MoultingYAML, and that would enable an easier definition of extractors from a path.
I have a yaml object which has been parsed successfully and I'm interested in just a couple of the keys. I'd like to be able to specify the paths for the keys and cast them to strings. Is there an easy way to do this? Couldn't see anything in the docs
The text was updated successfully, but these errors were encountered: