for-comprehension

    -1热度

    1回答

    愚蠢的基本问题,但我有以下列表: [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1]] 如何加入的元素结合在一起,所以它读取: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1] 干杯!

    5热度

    3回答

    在下面的代码段中, trait MyType1; trait MyType2 import scala.concurrent.Promise val p1 = Promise[Option[MyType1]]() val p2 = Promise[MyType2]() 我通过在p1和p2到另一个函数,其中我使用一个成功的未来完成的前景。呼叫此功能后,我尝试读取Promise中的值: t

    0热度

    1回答

    我的机器上有4个内核。 而且我认为换理解时间表的东西,在并联机器人(不能够在以前的result..same为flatMap依赖): val stuffResult: Future[String] = for { stuff1 <- service1.doServiceStuff("service 1") // worker-5 (4+1) stuff2 <- service1.

    2热度

    3回答

    我试图使用表达式来映射选项,但我只想匹配如果选项的内容是特定类型。我想会的工作是这样的: for { vcs: Mercurial <- maybeVcs } yield vcs 但是,这会产生以下编译错误: <console>:76: error: type mismatch; found : sbtrelease.Mercurial => sbtrelease.Mercuri

    1热度

    1回答

    鉴于返回Future以下方法... def getProducts: Future[List[Product]] = { ... } def sendOrder(p: Product, n: Int): Future[Order] = { ... } ...我需要调用sendOrder由getProducts,并在返回的每个产品结束yield加工产品数量: for { produc

    -1热度

    1回答

    我想创建一个通用的permutations函数。 def permutation(size: Int): Stream[List[Int]] = ... permutation(1) # same as: for { x <- (1 to 10).toStream } yield List(x) permutation(2) # same as: for { x <- (1 to 10).t

    2热度

    1回答

    给定一个更高的Kinded类型M和monad类型的类,我可以通过for-understanding理解M内的值。使用返回Options的函数,即时寻找一种更合适的方式来扁平化这些选项,而不是我的解决方案。这是如下 class Test[M[+_]:Monad](calc:Calculator[M]) { import Monad._ def doSomething(x:Flo

    0热度

    1回答

    是否有更多功能的方式来做到以下几点? if (myList.isEmpty) { println("Empty list") } else for (element <- myList) { println(element) } 也许是这样的: for (element <- myList) { println(element) } orElse {

    1热度

    2回答

    鉴于整数以下List ... val l = List(1, 2, 3) ...我需要调用2种方法,每个元素返回Future和得到以下结果: Future(Some(1), Some(2), Some(3)) 这下面是我的尝试: import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicit

    2热度

    1回答

    我正在寻找一种方法来捕获在理解本身的类型中用于理解的类型。为此,我所指定的粗糙界面: trait Chain[A]{ type ChainMethod = A => A //type of the method chained so far def flatMap[B](f: A => Chain[B]): Chain[B] //the ChainMethod needs t