Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement