Created
April 22, 2016 15:12
-
-
Save Dierk/f28befa736c4c1508235e7a03a486cae to your computer and use it in GitHub Desktop.
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
// Haskell-style iterate function in Groovy | |
Closure iterate(def value, Closure nextValue) { | |
return { value = nextValue value } | |
} | |
// use for iteration | |
def iter = iterate(0) { it + 1} | |
5.times { | |
println iter() | |
} | |
// use for fixpoint calculation | |
def fix = iterate(1.0) { Math.cos it} | |
while (fix() != fix()) {} | |
println fix() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment