谁能用ActorIdentity一个很好的例子来解释如何以及何时使用?
从文档中我可以发现“有一个内置的 Identity 消息,所有 Actor 都会理解该消息,并使用包含 ActorRef 的 ActorIdentity 消息自动回复”。
该声明是否意味着获得的演员说actorSelector我的演员中包含了 ActorIdentity 消息?
ActorSelection actorSelector = getContext().actorSelection("/A/B/*");
Run Code Online (Sandbox Code Playgroud) 我从斯卡拉看到层次即AnyVal是超级类型scala.Unit,Boolean,Char和其他Number类型.
scala> val list1 = List((), 1 )
list: List[AnyVal] = List((), 1) // I see this is valid when compared with hierarchy tree.
scala> val list2 = List(Unit, 1 )
list: List[Any] = List(object scala.Unit, 1) // Why???
Run Code Online (Sandbox Code Playgroud)
我看到的list1是型AnyVal,其中作为list2是类型的Any,即使它们具有相同的数据(我假设).
是()不是一样的Scala.Unit?我在这里错过了什么?
我有两个外部电话
我需要使用第一个电话中可用序列中的第二个电话来更新每个人的状态。这就是我尝试过的方式
getFuturePeople.map( (seqPeople : Seq[People]) => {
seqPeople.map(person => getStatus(person._id).status).map(status => {
//Update status for this person but I get Seq[Future[Peoson]]
})
})
Run Code Online (Sandbox Code Playgroud) 我需要编写一个对Seq[T]对象执行排序的通用代码。我知道这不会是可能执行排序操作,直到我们知道base class和它的attributes。在查看了这个答案之后,我使用了这段代码,我的要求是处理尽可能多的自定义数据类型。
case class Country(name: String, id : Int)
type CountrySorter = (Country, Country) => Boolean
def byName : CountrySorter = (c1:Country, c2:Country) => c1.name < c2.name
def byId : CountrySorter = (c1:Country, c2:Country) => (c1.id < c2.id)
val sortingMap = Map[String, CountrySorter](
"sortByCountryName" -> byName ,
"soryByCountryId" -> byId
)
Run Code Online (Sandbox Code Playgroud)
函数调用
def sort[T]( input : Seq[T], criteria : String) : Seq[T] = {
input.sortWith(sortingMap(criteria))
}
Run Code Online (Sandbox Code Playgroud)
input.sortWith(sortingMap(criteria))在这里我得到错误,因为sortWith函数只需要 …
我最近开始使用Meteor构建工具Chartist来表示我的数据。
我有图例模板的java脚本(来自互联网)
function drawBarChart() {
new Chartist.Bar('.legendChart1', {
labels: ['First quarter of the year', 'Second quarter of the year', 'Third quarter of the year', 'Fourth quarter of the year'],
series: [
{ "name": "Money A", "data": [60000, 40000, 80000, 70000] },
{ "name": "Money B", "data": [40000, 30000, 70000, 65000] }
]
}, {
plugins: [
Chartist.plugins.legend()
]
});
};
Template.legendTemplate.rendered = function(){
drawBarChart();
}
Run Code Online (Sandbox Code Playgroud)
<template name="legendTemplate">
<div class="legendChart1">
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
以及相应的导入语句
import {legend} …Run Code Online (Sandbox Code Playgroud) 我正在使用apache-commons-sanselan.jarAPI来删除EXIF仅来自JPEG文件的内容.
如何从其他文件扩展名中删除此内容?
我有一个类似的课程Pairs.我有一个特性,将此类转换Pairs为Json格式.
import scala.reflect.ClassTag
import spray.json._
import spray.json.DefaultJsonProtocol
case class Pairs[K, V](key:K, value: V)
trait Convertor[K, V] extends DefaultJsonProtocol{
implicit val convertor = jsonFormat2(Pairs[K, V])
}
val p = Pairs[String, Int]("One", 1)
println(p.toJson)
Run Code Online (Sandbox Code Playgroud)
当我使用这个特性时,我得到以下错误,以获得转换器K和V类型.
错误:找不到类型为Convertor.this.JF [K]隐式val转换器= jsonFormat2(Pairs [K,V])^的证据参数的隐式值
但是如何在范围内引入通用数据类型.有人可以帮帮我吗?
当使用matchin 组合多个案例时,是否可以给变量赋予引用名称Scala?
码:
假设Gender枚举有一个像三个可能的值male,female和other。
(nameOption, genderOption) match {
case (Some(name), Some(Gender.Male)) | (Some(name), Some(Gender.FeMale))=> s"$name gender is either male or female"
case (None, Some(Gender.Male)) | (None, Some(Gender.FeMale)) => //some print statement
case (Some(name), Some(Gender.Other)) => //some print statement
case _ => //some print statement
}
Run Code Online (Sandbox Code Playgroud)
第一种情况case (Some(name), Some(Gender.Male)) | (Some(name), Some(Gender.FeMale))是name在范围中已经定义的编译器错误。
如果在我的实际代码中不合并案例,则循环复杂性会增加。
查找给定的循环旋转是否string1可以产生string2?
例子:-
字符串 1 = abcd
字符串 2 = cdab
true字符串 1 = abc
字符串 2 = bac
false我试图通过减少从复杂性,以提高这种逻辑n^2来n,并n要n-k通过使该checkRotation功能在找到第一个之后终止true。
//complexity n^2
def checkRotation(string1: String, string2: String): Boolean = {
for (i <- 0 until string1.length) yield {
for (j <- 0 until string2.length) yield {
if (string1.charAt(i) == string2.charAt(j)) {
string1 == string2.substring(j) + "" + string2.substring(0, j) …Run Code Online (Sandbox Code Playgroud) scala ×6
akka ×1
chartist.js ×1
future ×1
hierarchy ×1
java ×1
javascript ×1
logic ×1
meteor ×1
meteor-blaze ×1
spray-json ×1