Skip to content

Instantly share code, notes, and snippets.

@smosher
Last active January 3, 2016 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smosher/8488715 to your computer and use it in GitHub Desktop.
Save smosher/8488715 to your computer and use it in GitHub Desktop.
Grep role for Sequences.
Regex
GrepRole := Object clone do(
grep := method(x,
self split("\n") select(
matchesOfRegex(x) map(k, k) size > 0
) map(k, k)
)
)
Sequence appendProto(GrepRole)
// Usage:
GrepRole
Socket slotSummary asString grep("connect" asRegex caseless) foreach(println)
// Nb. grep uses matchesOfRegex which will accept plain strings too.
/* Output:
Io> Socket slotSummary asString grep("connect" asRegex caseless) foreach(println)
asyncConnect = Socket_asyncConnect()
connect = method(...)
connectTimeout = 60
serverWaitForConnection = method(...)
setConnectTimeout = method(...)
syncConnect = method(...)
==> syncConnect = method(...)
Io>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment