nrinaudo on update-sbt-1.6.2
nrinaudo on master
Update sbt to 1.6.2 Merge pull request #141 from nr… (compare)
nrinaudo on update-sbt-1.6.2
Update sbt to 1.6.2 (compare)
nrinaudo on update-kantan.sbt-2.8.2
nrinaudo on master
Update to kantan.sbt 2.8.2 Merge pull request #140 from nr… (compare)
nrinaudo on update-kantan.sbt-2.8.2
Update to kantan.sbt 2.8.2 (compare)
In case that someone uses Intellij IDEA: I just added support for kantan.xpath to my plugin called Custom Postfix Templates. It allows you to easily expand
"//my/query".xp
to
xp"//my/query"
by automatically adding the following imports:
import kantan.xpath._
import kantan.xpath.implicits._
Please let me know if I can improve these postfix templates.
[not(.='')]
to the xpath query and it just works, but I wonder if there's more idiomatic way.
implicit val lenientStringDecoder: NodeDecoder[Option[String]] = NodeDecoder[Option[String]].map(_.filter(_ != ""))
T
, replace it with a new one adapted from it
I lost my first failed implementation and it's my second attempt without optionalDecoder
:
implicit def tolerantOptionDecoder[A](implicit ev: NodeDecoder[A]): NodeDecoder[Option[A]] =
NodeDecoder.from {
case Some(n) if n.getTextContent == "" => Right(None)
case n @ Some(_) => ev.decode(n).map(Some(_))
case None => Right(None)
}
I'm not sure if Node#getTextContent
makes sense here
NodeDecoder[Option[String]]
that's treats the empty string as a None
, or do you want something that treats the empty string as the absence of node?
contramap
on your decoder - turn Some(EmptyNode)
into Node
before the decoder is even called
def lenient[A: NodeDecoder](nonEmpty: A => Boolean) = NodeDecoder[Option[A]].map(_.filter(nonEmpty))
implicit val lenientString: NodeDecoder[Option[String]] = lenient(_ != "")
"<root id=''/>".evalXPath[Option[String]](xp"/root/@id")
// res1: kantan.xpath.XPathResult[Option[String]] = Right(None)
"<root id='foo'/>".evalXPath[Option[String]](xp"/root/@id")
// res2: kantan.xpath.XPathResult[Option[String]] = Right(Some(foo))
"<root/>".evalXPath[Option[String]](xp"/root/@id")
// res3: kantan.xpath.XPathResult[Option[String]] = Right(None)
XmlSource
type class, which provides the instance you need: https://github.com/nrinaudo/kantan.xpath/blob/master/core/src/main/scala/kantan/xpath/XmlSource.scala#L101
XmlSource[YourDocumentType]