Christian
Christian

Reputation: 646

clojure call function with result of itself in a loop

Is there a clojure function that can be called in a loop with feeding it with the result of the previous call?

Pseudo-code might be look like this:

currentValue = firstValue;
while (endNotYetReached(currentValue)) {
  currentValue = myFunction(currentValue);
}

Thank you for every answer!

Upvotes: 1

Views: 191

Answers (1)

kongeor
kongeor

Reputation: 732

You can use iterate, which returns an infinite lazy sequence, from which you can take, drop, etc:

=> (take 3 (iterate inc 5))
(5 6 7)

Upvotes: 5

Related Questions