小编jen*_*jen的帖子

使用一个服务调用(List)的结果来获取另一个List

我有一个服务返回一个数据类型(Foo下面),其中包含一个id列表,用于getBar下面的第二个服务调用

case class Foo(barIds: List[Int])
case class Bar(id: Int)

val f = Future(List(Foo(List(1, 2)), Foo(List(5, 6))))
def getBar(l: List[Int]) = Future(l.map(Bar(_)))
Run Code Online (Sandbox Code Playgroud)

我需要的是 Future[List[Foo,List[Bar]]]

我先尝试了一个嵌套的for-understanding,但是

val rr = for {
    foos <- f
} yield  for {
    foo <- foos
    bars <- getBar(foo.barIds) // won't work as this is a Future and foos is a list
} yield (foo,bars)   
Run Code Online (Sandbox Code Playgroud)

然后我玩了一个映射游戏,(闻起来很可怕):

f.map(
    foos => foos.map(foo => (foo, foo.barIds)))
        .map(ts => ts.map(t => (t._1, getBar(t._2)))
)
Run Code Online (Sandbox Code Playgroud)

但这给了我一个 Future[List[Foo,Future[List[Bar]]]]

应该有一种方式来获得 …

scala

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

在scala.js中使用日期时感到困惑

java.util.Date在一个同构类中使用aa :

case class RendezVous(var id: Option[String], var date : Date, var lieu : String)
Run Code Online (Sandbox Code Playgroud)

在页面上,日期显示为

{"date$1":"2015-05-06T07:10:47.433Z"}
Run Code Online (Sandbox Code Playgroud)

请问java.util.Date.scala没有在这个问题上帮助?如果没有那么我如何在jvm/js共享类中使用Date

scala.js

3
推荐指数
1
解决办法
1385
查看次数

如何使用带有 where 子句的 ScalikeJDBC 的返回()

我正在尝试将 PostgresRETURNING与 ScalikeJDBC一起使用(请参阅https://github.com/scalikejdbc/scalikejdbc/issues/559

这如何与where子句一起使用。的returning(...)是其成员UpdateSQLBuilder,而where返回一个ConditionSQLBuilder

update(Post)
   .set(sqls"${p.views}=${p.views}+${newViews}")
   .where.eq(p.id,id)
   .returning(p.id,p.lastUpdated, p.views) // does not work as it is not a member of ConditionSQLBuilder
Run Code Online (Sandbox Code Playgroud)

scala scalikejdbc

2
推荐指数
1
解决办法
310
查看次数

标签 统计

scala ×2

scala.js ×1

scalikejdbc ×1