Skip to content

Instantly share code, notes, and snippets.

@kevinwright
kevinwright / XML Traversal
Created September 30, 2011 08:34
Deeper than flatmap, taking on whole trees in one bite!
def flatTraverse[T](node: Node)(pfn: PartialFunction[Node, TraversableOnce[T]]): Seq[T] = {
traverse(node)(pfn).flatten
}
def traverse[T](node: Node)(pfn: PartialFunction[Node, T]): Seq[T] = {
def inner(n: Node, acc: List[T]): List[T] = n match {
case x if (pfn isDefinedAt x) => pfn(x) :: acc
case e: Elem => (e.child.toList map {inner(_, Nil)}).flatten ::: acc
case _ => acc
}
@jboner
jboner / SBT.sublime-build
Created May 6, 2011 09:47
Sublime Editor SBT build setup
{
"cmd": ["sbt-no-color compile"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true"
}