Skip to content

Instantly share code, notes, and snippets.

@gakuzzzz
Created July 2, 2011 00:03
Show Gist options
  • Save gakuzzzz/1059609 to your computer and use it in GitHub Desktop.
Save gakuzzzz/1059609 to your computer and use it in GitHub Desktop.
Generic な grep
implicit def toGrepCallable[A](list: Traversable[A]) = new {
def grep[B](regex: String)(func: A => B = identity _)(implicit v: A =:= String) =
list.collect {
case s if regex.r.findFirstIn(s).isDefined => func(s)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment