Created
August 25, 2017 11:30
-
-
Save EricLondon/22d2937a5204f8486131ca4fb7fadd84 to your computer and use it in GitHub Desktop.
scala-get-methods.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"" | |
.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