scala

Scala type constructors misunderstanding

I'm trying to write a method which takes a Map[K, Collection[V]] and converts it to a map with a different type of Collection for its values. The method takes the "multimap" and a builder that will construct the new collections. I use it like this: val multimap = new java.util.HashMap[Int, java.util.List[String]] multimap.put(1, Arrays....

ScalaTest: Issues with Singleton Object re-initialization

I am testing a parser I have written in Scala using ScalaTest. The parser handles one file at a time and it has a singleton object like following: class Parser{...} object Resolver {...} The test case I have written is somewhat like this describe("Syntax:") { val dir = new File("tests\\syntax"); val files = dir.listFiles.f...

Scala method that returns multiple concatenated filter functions

In my app, I'm filtering a file array by various types, like the following: val files:Array[File] = recursiveListFiles(file) .filter(!_.toString.endsWith("png")) .filter(!_.toString.endsWith("gif")) .filter(!_.toString.endsWith("jpg")) .filter(!_.toString.endsWith("jpeg")) .filter(!_.toString.endsWith("bmp")) .filter(!_.toSt...

Best way to change list type in scala

Hi all, I have a list in scala called l : List[AType] that I want to change to list[String]. This may sound like a very dirty, inefficient approach, but I'm not quite sure of the best way to do this. My code was: var result = new Array[String]("a","b") l foreach { case a => result = result :+ (a.toString().toUpperCase()); } result toL...

What are the differences between asInstanceOf[T] and (o: T) in scala ?

I saw that there is 2 methods to cast an object : foo.asInstanceOf[Bar] (foo: Bar) When I tried I found that as asInstanceOf don't use the implicit conversions whereas the other one do. So what are the differences of behavior between this 2 methods ? And where it's recommended to use one over the other ? Thank you. ...

Expected type of Parser in method "|"

I have the following code being compiled against scala 2.8.0: import scala.util.parsing.combinator.{syntactical,PackratParsers} import syntactical.StandardTokenParsers object MyParser extends StandardTokenParsers with PackratParsers{ lexical.reserved ++= Set("int","char","boolean") lazy val primitiveType:PackratParser[PrimitiveTyp...

Modifying watchpaths

SBT has triggered execution so if I execute a command like ~test It executes all test cases and then waits for source changes. I want to extend this behavior to get triggered execution whenever input files are changed. All input files exist in a single folder. To achieve this I created a scala file in project/buildfolder: import sbt....

Scala + stax compile problem during deploy process

Hello. I developed an app in scala-ide (eclipse plugin), no errors or warnings. Now I'm trying to deploy it to the stax cloud: $ stax deploy But it fails to compile it: compile: [scalac] Compiling 2 source files to /home/gleontiev/workspace/rss2lj/webapp/WEB-INF/classes error: error while loading FlickrUtils, Scala signature Flick...

Scala/Java servlets: How to output < in the HTML code instead of &lt;

I have a servlet coded in Scala. I have some code like this in there: def message = <HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>{value}</BODY></HTML> def value = "Hello <BR/> World" The corresponding HTML code generated for value is Hello &lt;BR/&gt; World How do I get it to generate the HTML code (shown below)? Hello <BR/> World...

Self type inheritance in scala

Say I have the following traits: trait A trait B { this: A => } trait C extends B // { this: A => } Compiler error: illegal inheritance; self-type C does not conform to B's selftype B with A As expected if I uncomment the self type annotation, the compiler is happy. I think it's quite obvious why C also needs this self type. What ...

How can I differentiate between def foo[A](xs: A*) and def foo[A, B](xs: (A, B)*)?

I know that type erasure makes them look equal, type-wise, at runtime, so that: class Bar { def foo[A](xs: A*) { xs.foreach(println) } def foo[A, B](xs: (A, B)*) { xs.foreach(x => println(x._1 + " - " + x._2)) } } gives the following compiler error: <console>:7: error: double definition: method foo:[A,B](xs: (A, B)*)Unit a...

Mixins vs composition in scala

In java world (more precisely if you have no multiple inheritance/mixins) the rule of thumb is quite simple: "Favor object composition over class inheritance". I'd like to know if/how it is changed if you also consider mixins, especially in scala? Are mixins considered a way of multiple inheritance, or more class composition? Is there...

Scala, Java and equality

val filesHere = (new java.io.File(".")).listFiles val filesHere2 = (new java.io.File(".")).listFiles scala> filesHere == filesHere2 res0: Boolean = false That is quite counter intuitive. I would rather expect that filesHere and filesHere2 are equal. This is certainly due to a semantics mismatch between Java and Scala, e.g., ab...

Adding divs to the HTML body using Lift

I have been playing around with Scala/Lift/Comet/Ajax etc. recently. I came across a problem which boils down to this: Summary I want to update a specific div (by id) when a certain event occurs. If the div does not exist yet, it must be created and appended to the HTML body. Currently I cannot get this to work when using the Lift fra...

Implement different stratum for Java Debugger Interface

In the Java Debugger Interface documentation for the Location class, there's a paragraph discussing the "stratum" of the location. I've been looking around a bit for more detail on how one would go about implementing a new stratum (for, say, Scala or JRuby), but I haven't found much. Can anyone shed some light on the topic? ...

Programming on Lift on Realtime - Is it possible?

I have been programming Rails and Lift for a while. Rails, said, a joy to work on. But Lift performance is too awesome to be ignored. However, I find building stuff inside Lift is way slower compare to rails. For example, whenever a change in Lift webapp is made, I need to request maven to recompile/retest the whole webapp (which is a re...

Data Structure To Store Arbitrary Database Tables

Hello, I'd like to design a JVM data structure (Java/Scala) that can be used to represent and store the contents of arbitrary relational database tables. The data structure should be fast (not too gc-intensive, cache-friendly) and memory efficient, so larger tables can fit in RAM. One memory-efficient solution is to store each column ...

What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

I can see in the API docs for Predef that they're subclasses of a generic function type (From) => To, but that's all it says. Um, what? Maybe there's documentation somewhere, but search engines don't handle "names" like "<:<" very well, so I haven't been able to find it. Follow-up question: when should I use these funky symbols/classe...

How to integrate Scala into core Android platform?

I am interested in integrating Scala (or some other non-Java JVM-language) into the android platform. I am not referring to writing an android application with Scala, that I did early early on, but actually hooking into the build process that builds the android platform source tree. I imagine this will be a matter of hooking into the mak...

java.util.concurrent.LinkedBlockingQueue put method requires Nothing as argument in Scala

Here is a snippet of the code- import java.util.concurrent.LinkedBlockingQueue def main(args:Array[String]) { val queue=new LinkedBlockingQueue queue.put("foo") } This gives me - error: type mismatch; found : java.lang.String("foo") required: Nothing queue.add("foo") My understanding is its bec...