if with recursion almost clear, for example
def product2(ints: List[Int]): Int = { @tailrec def productAccumulator(ints: List[Int], accum: Int): Int = { ints match { case Nil => accum case x :: tail => productAccumulator(tail, accum * x) } } productAccumulator(ints, 1) } I am not sure about to the corecursion. According to the Wikipedia article, "corecursion allows programs to produce arbitrarily complex and potentially infinite data structures, such as streams". For example construction like this
list.filter(...).map(...) makes to posible prepare temporary streams after filter and map operations. after filter stream will be collect only filtered elements, and next in the map we will change elements. Correct?
Do functional combinators use recursion executions for map filter Does any body have good example in Scala "comparing recursion and corecursion"?
productis corecursion.productas recursion would look likedef product(ints: List[Int]): Int = ints match { case Nil => 1 case x :: xs => x * product(xs) }Iterable<..>in Java-world