Created
January 6, 2012 04:10
-
-
Save yusuiked/1568915 to your computer and use it in GitHub Desktop.
リストとリストに対するフィルタリングの実装をクロージャとして渡してフィルタリングする
This file contains 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
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