我有一个服务返回一个数据类型(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]]]]
应该有一种方式来获得 …
我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
我正在尝试将 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)