Skip to content

Instantly share code, notes, and snippets.

@yusuiked
Created January 6, 2012 04:12
Show Gist options
  • Save yusuiked/1568919 to your computer and use it in GitHub Desktop.
Save yusuiked/1568919 to your computer and use it in GitHub Desktop.
フィルタリングの再帰バージョン。
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