到目前为止,我一直在用SBT编译我的Scala项目(通过Typesafe堆栈).我想通过sbt-assembly在几台机器上运行代码.按照指示,我所做的唯一一项更改是在我的project/Build.scala文件中.这是相关部分:
resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",
resolvers += "artifactory" at "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases",
libraryDependencies += "com.eed3si9n" % "sbt-assembly" % "0.8.3"
Run Code Online (Sandbox Code Playgroud)
sbt compile但是,当我运行时,我收到此错误:
sbt.ResolveException: unresolved dependency: com.eed3si9n#sbt-assembly/scala_2.9.1/sbt_0.11.2;0.8.3: not found.
我究竟做错了什么?
谢谢!
编辑build.sbt在与Build.scala(文件夹是/project/)相同的文件夹中
创建了一个文件,并在其中包含以下两行:
Seq[Setting[_]](resolvers += "artifactory" at "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases",
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.3"))
Run Code Online (Sandbox Code Playgroud)
现在的错误是:
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.eed3si9n#sbt-assembly;0.8.3: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check …Run Code Online (Sandbox Code Playgroud) 我有一个Iterator[Option[T]]和我想的Iterator[T]那些OptionS其中T isDefined.必须有一个比这更好的方法:
it filter { _ isDefined} map { _ get }
Run Code Online (Sandbox Code Playgroud)
我原本以为在一个结构中它是可能的......有人有什么想法吗?
Scala是否提供内置的类,实用程序,语法或其他机制来转换(通过换行)具有Iterable的Iterator?
例如,我有一个迭代器[Foo],我需要一个Iterable [Foo],所以目前我是:
val foo1: Iterator[Foo] = ....
val foo2: Iterable[Foo] = new Iterable[Foo] {
def elements = foo1
}
Run Code Online (Sandbox Code Playgroud)
这看起来很丑陋而且没必要.什么是更好的方式?
如果我Set使用Scala 创建Set(1, 2, 3)一个immutable.Set.
scala> val s = Set(1, 2, 3)
s: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
Q1:这实际上是什么样的套装?它是一些散列集吗?例如,查找的复杂性是多少?
Q2:我在哪里可以阅读这种"创建"方法?我认为这是apply方法,但文档说" 这个方法允许集合被解释为谓词.如果此集合包含元素elem,则返回true. "
同样,如果我创建一个List使用List(1, 2, 3),我得到
scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)
scala> l.getClass
res13: java.lang.Class[_] = class scala.$colon$colon
Run Code Online (Sandbox Code Playgroud)
Q3:再次,我得到了什么?在这种情况下,我甚至无法立即判断它是否可变,因为它甚至不是scala.collection-package的一部分.为什么这个包含在scala包中?
问题4:我可以在API中阅读有关"创建列表"方法的内容吗?
前段时间我正在阅读W3C关于" 重写脚本内容中使用字符串 "的文章,其中包含一些有关国际化的有用建议,但这让我感到不安,因为我们认为DRY(不要重复自己)消除重复代码的原则.
举个例子,我们可能会有这样的代码......
print "The printer is ";
if (printer.working) {
print "on.\n";
} else {
print "off.\n";
}
print "The stapler is ";
if (stapler.working) {
print "on.\n";
} else {
print "off.\n";
}
Run Code Online (Sandbox Code Playgroud)
我的直觉是大致消除重复如下......
report-state(printer, "printer");
report-state(stapler, "stapler");
function report-state(name, object) {
print "The "+name+" is ";
if (object.working) {
print "on\n";
} else {
print "off\n";
}
}
Run Code Online (Sandbox Code Playgroud)
...但是,如果我们需要将其本地化为西班牙语,那么这样做会导致代码出现问题,因为在这两种情况下,"on"这个词明显不同.
所以,我想我的问题是,其他开发人员如何平衡DRY原则与其代码的国际化?
我的一部分想要争辩说,国际化是" 你不会需要它 "的极端编程之一.然而,另一方面,考虑到DRY原则的重构应该通过使其易于实现所需的功能来平衡这一点,而不是像在这里那样更难.
我有一个我想要随机排列的数组.在Java中,有一个方法Collections.shuffle()可以随机地重新排列List的元素.它也可以在数组上使用:
String[] array = new String[]{"a", "b", "c"};
// Shuffle the array; works because the list returned by Arrays.asList() is backed by the array
Collections.shuffle(Arrays.asList(array));
Run Code Online (Sandbox Code Playgroud)
我尝试在Scala数组上使用它,但Scala解释器回答了一个冗长的答案:
scala> val a = Array("a", "b", "c")
a: Array[java.lang.String] = Array(a, b, c)
scala> java.util.Collections.shuffle(java.util.Arrays.asList(a))
<console>:6: warning: I'm seeing an array passed into a Java vararg.
I assume that the elements of this array should be passed as individual arguments to the vararg.
Therefore I follow the array with a `: _*', to mark …Run Code Online (Sandbox Code Playgroud) 我达到了这个目的:
implicit def collectionExtras[A](xs: Iterable[A]) = new {
def zipWith[B, C, That](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: CanBuildFrom[Iterable[A], C, That]) = {
val builder = cbf(xs.repr)
val (i, j) = (xs.iterator, ys.iterator)
while(i.hasNext && j.hasNext) {
builder += f(i.next, j.next)
}
builder.result
}
}
// collectionExtras: [A](xs: Iterable[A])java.lang.Object{def zipWith[B,C,That](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: scala.collection.generic.CanBuildFrom[Iterable[A],C,That]): That}
Vector(2, 2, 2).zipWith(Vector(4, 4, 4))(_ * _)
// res3: Iterable[Int] = Vector(8, 8, 8)
Run Code Online (Sandbox Code Playgroud)
现在问题是上面的方法总是返回一个Iterable.如何让它返回传递给它的类型集合?(在这种情况下,Vector)谢谢.
鉴于:
val list = List("one","two","three")
val it = list.toIterator
Run Code Online (Sandbox Code Playgroud)
我可以跑:
list map ("_" +) -> List(_one, _two, _three)
for (i <- list) yield("_" + i) -> List(_one, _two, _three)
Run Code Online (Sandbox Code Playgroud)
如果我在迭代器上运行相同的操作,我得到:
it map ("_" + ) -> Iterator[java.lang.String] = empty iterator
for (i <- it) yield("_" + i) -> Iterator[java.lang.String] = empty iterator
Run Code Online (Sandbox Code Playgroud)
在我运行map/for之后,我不应该再找回另一个(非空的)Iterator [String]吗?
我正在重构一个有效的ASP.NET Web应用程序,以使用ASP.NET Web Service公开Web服务接口.根据Web服务身份验证 - 最佳实践,基本身份验证通过https是可行的方法.让我们假设它是,而不是做WS-Security,X509等.
在.NET 3.5/VS 2008上,实现自定义http基本身份验证(非Windows帐户)的最简单方法是什么,例如,只接受用户名为"foo"且密码为"bar"的情况.最终,我想要Thread.CurrentPrincipal设定.
我是自己编写HttpModule还是可以更简单?
在Scala我希望能够写
val petMap = ImmutableMultiMap(Alice->Cat, Bob->Dog, Alice->Hamster)
Run Code Online (Sandbox Code Playgroud)
底层Map [Owner,Set [Pet]]应该同时具有Map和Set不可变.这是ImmutibleMultiMap与伴随对象的初稿:
import collection.{mutable,immutable}
class ImmutableMultiMap[K,V] extends immutable.HashMap[K,immutable.Set[V]]
object ImmutableMultiMap {
def apply[K,V](pairs: Tuple2[K,V]*): ImmutableMultiMap[K,V] = {
var m = new mutable.HashMap[K,mutable.Set[V]] with mutable.MultiMap[K,V]
for ((k,v) <- pairs) m.addBinding(k,v)
// How do I return the ImmutableMultiMap[K,V] corresponding to m here?
}
}
Run Code Online (Sandbox Code Playgroud)
你能优雅地解决评论线吗?地图和集合都应该是不可变的.
谢谢!
scala ×8
map ×2
.net-3.5 ×1
arrays ×1
asp.net ×1
collections ×1
for-loop ×1
immutability ×1
iterator ×1
jar ×1
list ×1
multimap ×1
sbt ×1
sbt-assembly ×1
scala-2.8 ×1
security ×1
set ×1
shuffle ×1
web-services ×1