scala-2.10

Default arguments to Scala's main function?

断了今生、忘了曾经 提交于 2019-12-12 15:41:46
问题 How do I get this to work, I've tried with and without new keyword: object Main extends App { override def main (args : Array[String] = new Array("default argument")) { println("args(0) = " + args(0)) } } http://ideone.com/5AyTxy (I have tried other [1, 2] methods but I think that its val is causing issues) Docs: http://docs.scala-lang.org/sips/completed/named-and-default-arguments.html#default_arguments PS: I should confirm that I want this to be bound to the args name; rather than to

Scala deserialization: class not found

点点圈 提交于 2019-12-12 10:48:17
问题 I'm trying to understand the following issue that occurs when trying to serialize/deserialize a very simple data structure: case class SimpleClass(i: Int) object SerializationDebug { def main(args: Array[String]) { val c = SimpleClass(0) val l1 = List(c) serializationSaveToFile("test", l1) val l2 = serializationLoadFromFile("test") // .asInstanceOf ... } def serializationSaveToFile(fn: String, o: Any) { val fos = new FileOutputStream(fn) val oos = new ObjectOutputStream(fos) oos.writeObject(o

How to use scala 2.10 trunk with sbt 0.11.0? (Unresolved dependencies)

六月ゝ 毕业季﹏ 提交于 2019-12-12 10:43:33
问题 What's the right way to use sbt with 2.10 trunk? I tried the obvious: james@James-Moores-iMac:~/workspace/Deleteme3$ cat build.sbt scalaVersion := "2.10.0-SNAPSHOT" But that gives: james@James-Moores-iMac:~/workspace/Deleteme3$ sbt compile [info] Loading global plugins from /Users/james/.sbt/plugins [info] Set current project to default-ee38f7 (in build file:/Users/james/workspace/Deleteme3/) [info] Updating {file:/Users/james/workspace/Deleteme3/}default-ee38f7... [info] Resolving org.scala

scala contravariant position on method

本小妞迷上赌 提交于 2019-12-11 20:58:16
问题 I was reading through http://oldfashionedsoftware.com/2008/08/26/variance-basics-in-java-and-scala/ and am looking at the code class CoVar[+T](param1: T) { def method1(param2: T) = { } def method2: T = { param1 } def method3: List[T] = { List[T](param1) } def method4[U >: T]: List[U] = { List[U](param1) } val val1: T = method2 val val2: Any = param1 var var1: T = method2 var var2: Any = param1 } then if I were to have a val covar1 = new CoVar(new Car) val covar2: CoVar[Vehicle] = covar1 /

scala Enumeration with constructor and lookup table

只谈情不闲聊 提交于 2019-12-11 14:59:43
问题 I saw the following solution for an enum somewhere object Day { val values = new ArrayBuffer[Day] case class Day(name:String) { values += this } val MONDAY = new Day("monday") val TUESDAY = new Day("tuesday") } This demonstrates what I am trying to go for EXCEPT there is a var hidden in the ArrayBuffer....that is kind of icky. What I really want is a val lookupTable = Map() where when a request comes in, I can lookup "monday" and translate it to my enum MONDAY and use the enum throughout the

Can I build update query with variable fields without using plain SQL?

邮差的信 提交于 2019-12-11 13:17:33
问题 Can I build update query with variable number of fields without using plain SQL ? For example update of single column is simple - I just yield it to create narrow query. Query(RolesTable).filter((role: RolesTable.type) => role.id === role_id).map((role: RolesTable.type) => role.name).update(name) But what if Role has 5 fields and I want to allow API client to send me fields he wants to update ? How would I construct such query ? 回答1: The key here is to use the ~ operator when yielding the

Scala 2.10 reflection: ClassSymbol.isCaseClass works in scala console but not in script/app

孤者浪人 提交于 2019-12-11 12:47:14
问题 I am playing around with reflection in Scala 2.10.0-M7 and stumbled upon the ClassSymbol.isCaseClass method which behaves like expected in the scala console but not when executed as a java application or as a scala script. I've defined TestScript.scala like this: import reflect.runtime.currentMirror case class TestCase(foo: String) object Test { def main(args: Array[String]) { val classSymbol = currentMirror.reflect(new TestCase("foo")).symbol val isCaseClass = classSymbol.isCaseClass println

How can I use library which is built using 2.9.2 in project which is built using 2.10.1?

China☆狼群 提交于 2019-12-11 02:21:50
问题 How can I use library build against 2.9.2 in project which is built using 2.10.1 ? In particular I'm trying to use salat and get following exception sbt.ResolveException: unresolved dependency: com.novus#salat_2.10;1.9.2-SNAPSHOT: not found at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:214) at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122) at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121) at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)

Best way to validate and extend constructor parameters in Scala 2.10

随声附和 提交于 2019-12-11 01:57:34
问题 I want to have a class that has a number of fields such as String, Boolean, etc and when the class is constructed I want to have a fieldname associated with each field and verify the field (using regex for strings). Ideally I would just like specify in the constructor that the parameter needs to meet certain criteria. Some sample code of how : case class Data(val name: String ..., val fileName: String ...) { name.verify // Access fieldName associated with the name parameter. println(name

Scala: class type required but T found

橙三吉。 提交于 2019-12-11 01:25:59
问题 I've found similar issues of this particular problem, however the problem was due to someone trying to instantiate T directly. Here I'm trying to create a trait that is a general interface to extend classes and store them automatically in a database such as Riak using classOf[T] . Using Scala 2.10. Here's my code: trait RiakWriteable[T] { /** * bucket name of data in Riak holding class data */ def bucketName: String /** * determine whether secondary indices will be added */ def enable2i: