-
0 votesanswersviews
Scala:在for-comprehension中迭代Array的索引,但确保结果类型是相同的Array类型
我知道在for-comprehension中找到的第一个序列的序列类型定义了理解的输出类型 . 但是我需要在不牺牲理解语法的情况下解决这个问题 . 假设我有一些 Array[Double] 被称为 v 和一些复杂的谓词函数 condition ,它基于 v 的索引,如果 condition(i) 的计算结果为true,那么我想保留 v 的元素 . 它类似于使用 filter ,除了过滤发生在索引上... -
11 votesanswersviews
返回Scala for / yield的类型
我正在阅读Scala for the Impatient并且我让我挠头 . 以下返回String: scala> for ( c<-"Hello"; i <- 0 to 1) yield (c+i).toChar res68: String = HIeflmlmop 但是这会返回一个Vector: scala> for (i <- 0 to 1;... -
34 votesanswersviews
Scala for-comprehensions中的未来[选项]
我有两个返回期货的功能 . 我试图使用for-yield理解将第一个函数的修改结果输入到另一个函数中 . 这种方法有效: val schoolFuture = for { ud <- userStore.getUserDetails(user.userId) sid = ud.right.toOption.flatMap(_.schoolId) s <- sch...