-
-
Save dexterous/4080178 to your computer and use it in GitHub Desktop.
Function currying and scope in groovy
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 sum = { it.sum() } | |
def square = { it * it } | |
def ofEach = { Object[] l -> l.&collect } | |
sumOfSquares = sum << { it(square) } << ofEach | |
def sumOfSquaresOfTwoLargestNumbers(a, b, c) { | |
def l = [a, b, c] | |
l -= l.min() | |
sumOfSquares(*l) | |
} | |
println sumOfSquaresOfTwoLargestNumbers(1, 3, 4) | |
println sumOfSquaresOfTwoLargestNumbers(3, 4, 1) | |
println sumOfSquaresOfTwoLargestNumbers(4, 1, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment