如果我发送相同的消息,告诉和转发有什么区别:
case msg: Message =>
otherActor tell (msg,sender)
Run Code Online (Sandbox Code Playgroud)
和
case msg: Message =>
otherActor forward msg
Run Code Online (Sandbox Code Playgroud) 如何在scala中转换Option[Future[T]]为Future[Option[T]]?
我想用它:
val customerAddresses = for {
a <- addressDAO.insert(ca.address) // Future[Address]
ia <- ca.invoiceAddress.map(addressDAO.insert) // Option[Future[Address]]
} yield (a, ia) // Invalid value have to be two futures
Run Code Online (Sandbox Code Playgroud)
这里签名插入方法
def insert(address: Address): Future[Address]
Run Code Online (Sandbox Code Playgroud)
ca 是CustomerData
case class CustomerData(address: Address, invoiceAddress: Option[Address])
Run Code Online (Sandbox Code Playgroud) 是否有可能以Either类似的方式处理Option?在Option,我有一个getOrElse功能,在Either我想要返回Left或处理Right.我正在寻找最快的方法,没有任何样板:
val myEither:Either[String, Object] = Right(new Object())
myEither match {
case Left(leftValue) => value
case Right(righValue) =>
"Success"
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Java 1.8lambda表达式Idea UI Designer,我在maven中:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
和依赖
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用lambdas时,它返回编译错误:
Failed to execute goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 (default) on project stockbox-chart: Execution default of goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 failed: 52264 -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
你有什么想法如何使用lambdas Idea UI Designer?
我正在使用Scala的2.2版本,如何从build.sbt获取版本?
name := "project_name"
version := "0.2-SNAPSHOT"
play.Project.playScalaSettings
Run Code Online (Sandbox Code Playgroud)
或者我如何从另一个对象传递值?
我有一个Actor,在某些消息上我正在运行一些返回Future的方法.
def receive: Receive = {
case SimpleMessge() =>
val futData:Future[Int] = ...
futData.map { data =>
...
}
}
Run Code Online (Sandbox Code Playgroud)
是否可以通过实际上下文来等待这些数据?或者Await,如果我在SimpleMessage中需要这些数据,我能做的最好吗?
如何根据time字段获取第一个和最后一个文档.我可以使用$group和获取$first并$last记录,但我不需要在这里分组,只需获得第一个和最后一个完整的文档.也许我可以使用slice?此查询不起作用:
{
"aggregate": "353469045637980_data",
"pipeline": [
{
"$match": {
"$and": [
{
"time": {
"$gte": 1461369600
}
},
{
"time": {
"$lt": 1461456000
}
}
]
}
},
{
"$project": {
"first": {
"$slice": 1
},
"last": {
"$slice": -1
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud) mongodb mongodb-query aggregation-framework mongodb-aggregation
是否可以向JsObject添加新字段?
val jsonObj = Json.obj()
jsonObj.put("field" -> 100) <==== Somthing like this
Run Code Online (Sandbox Code Playgroud)
我有很多方法可以添加新字段.如何动态创建JsObject?
如何避免使用!!类的可选属性
class PostDetailsActivity {
private var post: Post? = null
fun test() {
if (post != null) {
postDetailsTitle.text = post.title // Error I have to still force using post!!.title
postDetailsTitle.author = post.author
Glide.with(this).load(post.featuredImage).into(postDetailsImage)
} else {
postDetailsTitle.text = "No title"
postDetailsTitle.author = "Unknown author"
Toast.makeText(this, resources.getText(R.string.post_error), Toast.LENGTH_LONG).show()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我应该创建一个局部变量吗?我认为使用!!不是一个好习惯