7

を持っているとしIterator[A]ます。scalaz streamに変換したいProcess[Nothing, A]と思います。

import scalaz.stream._

def foo[A](it: Iterator[A]): Process[Nothing, A] = ???

どのように実装しfooますか?

4

1 に答える 1

8

私はあなたがそれを使用してそれを行うことができると思いますunfold:

import scalaz.stream._

def foo[A](it: Iterator[A]): Process[Nothing, A] = Process.unfold(it) { it =>
  if (it.hasNext) Some((it.next, it))
  else None
}

例:

scala> foo(List(1,2,3,4,5).iterator).toList
res0: List[Int] = List(1,2,3,4,5)
于 2015-10-19T10:12:27.623 に答える