将Enumeratee转换为Future[List] Scala

4
在Play Scala框架中,将Enumerator转换为Future[List]的标准方法是什么?
1个回答

5
你可以使用带有类型为Iteratee[E,List [E]]的参数的run方法来获取Future [List [E]]
还有一个名为getChunks的方法,它创建Iteratee[E,List [E]]
myEnumerator run Iteratee.getChunks

你可以使用 Iteratee.fold 手动创建这样的 Iteratee。如果你想保留元素顺序,可以在 List 上使用 reverse
myEnumerator run Iteratee.fold(List.empty[E]){ (l, e) => e :: l } map { _.reverse }

2
或者您可以使用 Iteratee.getChunks,它可以为您精确地完成这个任务。 - Travis Brown

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接