我对Scala varargs有一个基本的了解:接受varargs的方法的参数需要暗示它是一个varargs使用_*.使用Scala 2.10.3,我定义了以下两种方法
scala> def method(varargs:Int*)(more:String*) = println(varargs,more)
method: (varargs: Int*)(more: String*)Unit
scala> val method2 = method(1,2,3)_
method2: Seq[String] => Unit =
Run Code Online (Sandbox Code Playgroud)
使用List或Range直接调用它们可以正常工作
scala> val paramList = List("hi","ho")
paramList: List[java.lang.String] = List(hi, ho)
scala> method2(paramList)
(WrappedArray(1, 2, 3),List(hi, ho))
scala> val range = (1 to 5) map {_.toString}
range: scala.collection.immutable.IndexedSeq[String] = Vector(1, 2, 3, 4, 5)
scala> method2(range)
(WrappedArray(1, 2, 3),Vector(1, 2, 3, 4, 5))
Run Code Online (Sandbox Code Playgroud)
为什么当我通过归因于参数调用它们时_*,我得到错误?
scala> method2(paramList:_*)
<console>:11: error: type mismatch;
found : …Run Code Online (Sandbox Code Playgroud) 这是我目前使用的代码
val bytes = new Array[Byte](20)
scala.util.Random.nextBytes(bytes)
sendAndReceive(bytes)
Run Code Online (Sandbox Code Playgroud)
有没有办法把它变成一个班轮?例如,如果它是一个Integer数组,我可以做
sendAndReceive(Array.fill(20){scala.util.Random.nextInt(9)}
Run Code Online (Sandbox Code Playgroud)
更换nextInt用nextBytes不起作用,因为的nextBytes需要一个Array[Byte]作为参数,而不是返回一个字节.
我想在上传之前检查文件类型:
content = self.cleaned_data['picture']
content_type = content.content_type.split('/')[0]
Run Code Online (Sandbox Code Playgroud)
上传图片时出现错误:
'NoneType' object has no attribute 'content_type'
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?
如何从源代码构建Go项目,而不是使用go get domain.com/dir/project?例如,而不是
go get github.com/kr/godep
我想从源代码构建:
git clone https://github.com/kr/godep.git
cd godep
GOPATH=/tmp/godep go build
Run Code Online (Sandbox Code Playgroud)
上面的命令将导致
dep.go:4:2: cannot find package "code.google.com/p/go.tools/go/vcs" in any of:
/usr/local/Cellar/go/1.2/libexec/src/pkg/code.google.com/p/go.tools/go/vcs (from $GOROOT)
/Users/hanxue/Source/godep/godep/src/code.google.com/p/go.tools/go/vcs (from $GOPATH)
save.go:5:2: cannot find package "github.com/kr/fs" in any of:
/usr/local/Cellar/go/1.2/libexec/src/pkg/github.com/kr/fs (from $GOROOT)
/Users/hanxue/Source/godep/godep/src/github.com/kr/fs (from $GOPATH)
Run Code Online (Sandbox Code Playgroud)
注意:走1.2安装在/usr/local/Cellar/go/1.2从一个链接/usr/local/Cellar/go/1.2/bin/go到/usr/local/bin/go
目前我的代码需要类转换
val dataWriter: BytesDataWriter = createDataWriter
def createDataWriter(p: SomeClass) =
p.create_datawriter().asInstanceOf[BytesDataWriter]
Run Code Online (Sandbox Code Playgroud)
该create_datawriter方法将返回超类DataWriter.asInstanceOf我尝试了这种方法,而不是使用它
val dataWriter: BytesDataWriter = createDataWriter(p) match {
case writer: BytesDataWriter => writer
case _ => throw new ClassCastException
}
Run Code Online (Sandbox Code Playgroud)
这太冗长了,如果情况不起作用.是否有更好的替代类铸造?
我想确定我拥有(下载)的缓冲区是否是图像文件,而不将其保存到磁盘。我查了一下,发现:
有没有更好的办法?
python identification python-imaging-library python-magic imghdr
我正在使用第三方库,其中异常导致类型的类RETCODE_ERROR.这是层次结构的选择.

不确定类是否实现Throwable,我希望模式匹配超类RETCODE_ERROR.
try {
// perform action here
} catch {
case e.asInstanceOf[RETCODE_ERROR] => // handle exception
}
Run Code Online (Sandbox Code Playgroud)
这有用,还是有更好的方法?
我一直在尝试使用jQuery来重置表单
$('#check_in_form')[0].reset();
不行.使用trigger()也不起作用
$('#check_in_form').trigger("reset");
当我使用这两种方法时,我在浏览器控制台上收到此错误
TypeError: $(...)[0].reset is not a function
使用普通的Javascript也不行.
getElementById("check_in_form").reset();
我终于不得不求助于"点击"重置按钮
$('#reset').click();
这可能是什么问题?jQuery正在处理这个页面,因为我非常依赖它来处理页面的其他部分.
我正在将我的项目从 Webpack 3 迁移到 Webpack 4,并且我想替换extract-text-webpack-plugin为mini-css-extract-plugin.
我的 webpack 配置有这个部分
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
Run Code Online (Sandbox Code Playgroud)
显然我不能执行return MiniCssExtractPlugin.extract({/*..*/}).
的等效语法是mini-css-extract-plugin什么?
完整的 webpack 配置https://gist.github.com/hanxue/74691af423247c9028c7ff811f373608
有了这个代码
"test\536".replace(/'/g, "")
我希望与原始字符串没有区别,因为没有单引号。但我得到了这个
"test+6"
当我用单引号在字符串上运行它时,它按预期工作
"test'536".replace(/'/g, "")
"test536"
Run Code Online (Sandbox Code Playgroud)