While going thru the “Impossible For A Beginner To Read” book titled ‘Functional Programming In Scala’ by Paul Chiusano and Rúnar Bjarnason
Published by Manning Publications, 2014, I came across this interesting implementation of the “zipAll” function. This one I really find hard to completely understand due to the use of the ‘->’ symbol. Is there a Scala Guru in here that has the time to describe in English how this implementation is working. I can “sort of” understand most of it but I cannot find any explanation of the use of the ‘->’ in the implementation, though thru tracing the code it is sort of apparent. Just wondering if someone can describe its usage here to help enlighten us beginners a little as to its usage. I will post the code below but first need to explain a few things for those that have not attempted to read that book. The author creates an implementation of a Stream object that is used in the implementation of zipAll. So you can take that for granted; Also, Cons is used to construct Streams.
now here is the implementation of zipAll:
def zipAll[B](s2: Stream[B]): Stream[(Option[A], Option[B])] =
zipWithAll(s2)((_, _))
def zipWithAll[B, C](s2: Stream[B])(f: (Option[A], Option[B]) => C): Stream[C] =
Stream.unfold((this, s2)) {
case (Empty, Empty) => None
case (Cons(h, t), Empty) => Some(f(Some(h()), Option.empty[B]) -> (t(), empty[B]))
case (Empty, Cons(h, t)) => Some(f(Option.empty[A], Some(h())) -> (empty[A] -> t()))
case (Cons(h1, t1), Cons(h2, t2)) => Some(f(Some(h1()), Some(h2())) -> (t1() -> t2()))
}
My main question is regarding the use of the -> in the code above.