The recursion is cool, but kind of low-level when you surround the library functions of a higher order. I am trying to avoid writing a recursive function to a process that depends on the last generated value.
I usually used a iteratefunction in Clojure over an “encrypted” list of the last value and current parameter. Is there an equivalent function in the Scala API?
Here is an abstract example attempt in some crazy pseudo-code:
Say what you have
and you want to copy all the generated values.
I am trying to avoid writing something similar to:
def f(ls:Seq[Int]):Seq[Float] = {
def g(pos:Int, lastGen:Float):Seq[Float] = {
val v = gen(lastGen, ls(pos))
if( end(v) )
Seq(v)
else
Seq(v) ++ g(pos+1, v)
}
f(0, 1)
}
- Fibonacci Haskell, , , , Clojure .
user1250537