Created
February 8, 2019 03:41
-
-
Save pradhyu/7687aa66c276ba0ddcbea8e208fe0fd7 to your computer and use it in GitHub Desktop.
Curry functions in groovy
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
@Grab('commons-lang:commons-lang:2.5') | |
import org.apache.commons.lang.RandomStringUtils as RSU | |
def randomClosure = { size, letters, numbers -> | |
// Invoke RandomStringUtils.random() method | |
RSU.random size, letters, numbers | |
} | |
def randomNumbers = randomClosure.rcurry(false, true) // letters = false, numbers = true | |
def randomLetters = randomClosure.ncurry(1, true, false) // letters = true, numbers = false | |
println randomClosure(10, true, true) // Sample output: VG7mffNAdA | |
println randomNumbers(10) // Sample output: 8099670444 | |
println randomLetters(10) // Sample output: ZOHlHewEPU |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment