Created
January 6, 2012 04:12
-
-
Save yusuiked/1568919 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) { | |
if (list.size() == 0) return list | |
if (p(list.head())) | |
[] + list.head() + filter(list.tail(), p) | |
else | |
filter(list.tail(), p) | |
} | |
l = filter(1..20, {n-> n % 2 == 0}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment