Scalaz module

kantan.xpath has a scalaz module that is, in its current incarnation, fairly bare bones: it provides decoders for Maybe and \/ as well as a few useful type class instances.

The scalaz module can be used by adding the following dependency to your build.sbt:

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

You then need to import the corresponding package:

import kantan.xpath.scalaz._

\/ decoder

The scalaz module provides a NodeDecoder instance for \/: for any type A and B that each have a NodeDecoder instance, there exists a NodeDecoder instance for A \/ B.

First, a few imports:

import scalaz._
import kantan.xpath.implicits._

We can then simply write the following:

"<foo><bar value='1'/><bar value='foo'/></foo>".evalXPath[List[Int \/ String]](xp"//bar/@value")
// res0: kantan.xpath.package.XPathResult[List[Int \/ String]] = Right(
//   value = List(-\/(a = 1), \/-(b = "foo"))
// )

Maybe decoder

The scalaz module provides a NodeDecoder instance for Maybe: for any type A that has a NodeDecoder instance, there exists a NodeDecoder instance for Maybe[A].

"<foo><bar/></foo>".evalXPath[Maybe[Int]](xp"//bar/@value")
// res1: kantan.xpath.package.XPathResult[Maybe[Int]] = Right(value = Empty())

Scalaz instances

The following instance for cats type classes are provided:


Other tutorials: