Libra module

kantan.xpath comes with a libra module that can be used by adding the following dependency to your build.sbt:

libraryDependencies += "com.nrinaudo" %% "kantan.xpath-libra" % "0.5.3"

You then need to import the corresponding package:

import kantan.xpath.libra._

And that’s pretty much it. You can now decode refined types directly.

Let’s first set our types up:

import libra._
import kantan.xpath.implicits._

type Duration = QuantityOf[Int, Time, Second]

We can then simply write the following:

"<foo><bar duration='1'/></foo>".evalXPath[Duration](xp"//bar/@duration")
// res0: kantan.xpath.package.XPathResult[Duration] = Right(
//   value = Quantity(value = 1)
// )

Other tutorials: