It is necessary to write the map implementation using the terms of the unfold function in the Scala language. It should look like this in the end:

def map[B](a :List[A])(f: A => B): Stream[B] = unfold()()

Accordingly, it is necessary to pass the correct arguments to the unfold function.

Here is the implementation of the unfold function:

def unfold[A, S](z: S)(f: S => Option[(A, S)]): Stream[A] = f(z) match { case Some((a, s)) => Stream.cons(a, unfold(s)(f)) case None => Stream.empty }

I beg for help.

    1 answer 1

     def unfold[A, S](z: S)(f: S => Option[(A, S)]): Stream[A] = f(z) match { case Some((a, s)) => Stream.cons(a, unfold(s)(f)) case None => Stream.empty } trait F[C] { def map[A](a: List[C])(f: C => A): Stream[A] = { def foo(li: List[C]): Option[(A, List[C])] = li match { case head :: body => Some(f(head) -> body) case Nil => None } unfold(a)(foo) } } // Проверка val stream = new F[Int]{}.map(List(1, 2, 3))(_ * 2) stream.mkString(",") //res0: String = 2,4,6