Skip to content

Instantly share code, notes, and snippets.

@yusuiked
Created January 6, 2012 04:10
Show Gist options
  • Save yusuiked/1568915 to your computer and use it in GitHub Desktop.
Save yusuiked/1568915 to your computer and use it in GitHub Desktop.
リストとリストに対するフィルタリングの実装をクロージャとして渡してフィルタリングする
def filter(list, p) {
def new_list = []
list.each { i ->
if (p(i))
new_list << i
}
new_list
}
modBy2 = { n -> n % 2 == 0}
l = filter(1..20, modBy2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment