Created
April 13, 2015 01:42
-
-
Save dagezi/cb6f72373702cb0895bb to your computer and use it in GitHub Desktop.
Groovy has real closure!
This file contains hidden or 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 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