相关疑难解决方法(0)

\/Scalaz中的"ap"有什么作用?

我正在研究scalaz的析类型,我注意到了方法ap

  /** Apply a function in the environment of the right of this disjunction. */
  def ap[AA >: A, C](f: => AA \/ (B => C)): (AA \/ C) =
    f flatMap (ff => map(ff(_)))

我想我明白它的作用.现在我想知道何时以及为什么要实际使用它?有没有使用此ap功能的例子?

scala scalaz

7
推荐指数
1
解决办法
562
查看次数

为什么这个未来的列表转换列表编译和工作?

免责声明:下面的代码片段与正在进行的Coursera课程之一相关.我们认为它只是出于学习目的而发布,不应该用于提交作为家庭作业的解决方案.

正如下面的评论所述,我们需要将Futures列表转换为列表的单个Future.更重要的是,如果至少有一个输入期货失败,那么最终的未来将会失败.

我遇到了以下实现,我完全不明白.

/** Given a list of futures `fs`, returns the future holding the list of values of all the futures from `fs`.
 *  The returned future is completed only once all of the futures in `fs` have been completed.
 *  The values in the list are in the same order as corresponding futures `fs`.
 *  If any of the futures `fs` fails, the resulting future also fails.
 */
def all[T](fs: List[Future[T]]): Future[List[T]] = 
             fs.foldRight(Future(Nil:List[T]))((f, fs2) =>
  for { …
Run Code Online (Sandbox Code Playgroud)

scala future for-comprehension

6
推荐指数
1
解决办法
2866
查看次数

标签 统计

scala ×2

for-comprehension ×1

future ×1

scalaz ×1