小编Pun*_*y V的帖子

如何以及何时在 Akka 中使用 ActorIdentity

谁能用ActorIdentity一个很好的例子来解释如何以及何时使用?

从文档中我可以发现“有一个内置的 Identity 消息,所有 Actor 都会理解该消息,并使用包含 ActorRef 的 ActorIdentity 消息自动回复”。

该声明是否意味着获得的演员说actorSelector我的演员中包含了 ActorIdentity 消息?

ActorSelection actorSelector =  getContext().actorSelection("/A/B/*");
Run Code Online (Sandbox Code Playgroud)

akka

5
推荐指数
1
解决办法
727
查看次数

scala.Unit和()不一样吗?

我从斯卡拉看到层次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?我在这里错过了什么?

scala hierarchy

5
推荐指数
1
解决办法
95
查看次数

如何获取Future [Seq [Person]]而不是Seq [Future [Person]]

我有两个外部电话

  1. 这给Future [Seq [People]]
  2. 它将person_id并返回person_status作为Future [String]

我需要使用第一个电话中可用序列中的第二个电话来更新每个人的状态。这就是我尝试过的方式

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)

scala future

4
推荐指数
2
解决办法
1110
查看次数

对通用对象列表进行排序

我需要编写一个对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函数只需要 …

scala

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

类型错误:Chartist.plugins.legend 不是函数

我最近开始使用Meteor构建工具Chartist来表示我的数据。

我有图例模板的java脚本(来自互联网)

模板.js

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)

HTML

<template name="legendTemplate">
<div class="legendChart1">
</div>
</template>
Run Code Online (Sandbox Code Playgroud)

以及相应的导入语句

 import {legend} …
Run Code Online (Sandbox Code Playgroud)

javascript meteor meteor-blaze chartist.js

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

如何使用Java API从TIFF,PNG的图像文件中删除EXIF内容

我正在使用apache-commons-sanselan.jarAPI来删除EXIF仅来自JPEG文件的内容.

如何从其他文件扩展名中删除此内容?

java

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

Spray Json:将Generic类型转换为JsonFormat

我有一个类似的课程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)

当我使用这个特性时,我得到以下错误,以获得转换器KV类型.

错误:找不到类型为Convertor.this.JF [K]隐式val转换器= jsonFormat2(Pairs [K,V])^的证据参数的隐式值

但是如何在范围内引入通用数据类型.有人可以帮帮我吗?

scala spray-json

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

合并多个案例时如何引用变量?

当使用matchin 组合多个案例时,是否可以给变量赋予引用名称Scala

码:

假设Gender枚举有一个像三个可能的值malefemaleother

(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在范围中已经定义的编译器错误。

如果在我的实际代码中不合并案例,则循环复杂性会增加。

scala

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

改进逻辑以在给定的 string1 上找到循环旋转可以产生 string2

查找给定的循环旋转是否string1可以产生string2

例子:-

字符串 1 = abcd

字符串 2 = cdab

输出 = true

字符串 1 = abc

字符串 2 = bac

输出 = false

我试图通过减少从复杂性,以提高这种逻辑n^2n,并nn-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)

logic scala

0
推荐指数
1
解决办法
60
查看次数