Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Created August 25, 2017 11:30
Show Gist options
  • Save EricLondon/22d2937a5204f8486131ca4fb7fadd84 to your computer and use it in GitHub Desktop.
Save EricLondon/22d2937a5204f8486131ca4fb7fadd84 to your computer and use it in GitHub Desktop.
scala-get-methods.scala
""
.getClass.getMethods.map(_.getName) // methods
.sorted // sort
.filter(_ matches "(?i).*index.*") // grep /index/i
/////////
implicit def toMethods(obj: AnyRef) = new {
def methods = obj.getClass.getMethods.map(_.getName)
}
implicit def toGrep[T <% Traversable[String]](coll: T) = new {
def grep(pattern: String) = coll filter (pattern.r.findFirstIn(_) != None)
def grep(pattern: String, flags: String) = {
val regex = ("(?"+flags+")"+pattern).r
coll filter (regex.findFirstIn(_) != None)
}
}
"".methods.sorted grep ("index", "i")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment