Skip to content

Instantly share code, notes, and snippets.

@dagezi
Created April 13, 2015 01:42
Show Gist options
  • Save dagezi/cb6f72373702cb0895bb to your computer and use it in GitHub Desktop.
Save dagezi/cb6f72373702cb0895bb to your computer and use it in GitHub Desktop.
Groovy has real closure!
def bank(int amount) {
[withdraw: {n -> amount -= n},
deposit: {n -> amount += n},
check: {amount}]
}
account = bank(1000)
println account.check()
println account.withdraw(100)
println account.deposit(300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment