scala

Performing complicated XPath queries in Scala

What's the simplest API to use in scala to perform the following XPath queries on a document? //s:Annotation[@type='attitude']/s:Content/s:Parameter[@role='type' and not(text())] //s:Annotation[s:Content/s:Parameter[@role='id' and not(text())]]/@type (s is defined as a nickname for a particular namespace) The only documentation I ca...

using scala jar from java project in NetBeans

I'm developing a scala library, which I would like to be used by java applications. If I set up a java project in netbeans, with a reference to the scala library (jar), I can compile the java project without errors. However I get problems when running the java project directly from netbeans (code from scala library is not executed e.g...

Is variance of for generic type parameters in C# 4.0 a step closer for higher kind types?

We know that implementing classes are still invariant, despite the fact that their interfaces are variant. However I am inquiring, is cov/contravariance a step closer to parametric polymorphism or these are two separate concepts? ...

Scala Unit type

I use opencsv to parse csv files, and my code is while( (line = reader.readNext()) != null ) { .... } I got a compiler warning saying: comparing values of types Unit and Null using `!=' will always yield true [warn] while( (aLine = reader.readNext()) != null ) { How should I do the while loop? ...

where do i put html files in my web-app folder for a lift project with maven?

I'm new to Lift framework for scala. For some reason, index.html resides in the web-app directory, and when I start up jetty, http://localhost:8080/ will point to that index.html file just fine. However, if I put a login.html file in the same folder as the index.html, and then go http://localhost:8080/login, Lift does not serve the file....

passing classpath to custom tasks in java/scala based project within buildr

I am using buildr to build my scala project and suppose I want to run a main program among the source code, I need to define custom task within buildr which is very easy. However, how can I pass the classpath dependency automatically?(i.e) suppose you have a large number of jar files added already as dependency within buildr. Is there an...

Issuing native system commands in Scala

I want to issue a native system command from a Scala program, and perhaps trap the output. ("ls" comes to mind. There may be other ways to get directory information without issuing the command, but that's beside the point of my question.) It would correspond to os.system(...) in Python. I've looked in "Programming in Scala". I've looked...

Scala n00b: Critique my code

G'day everyone, I'm a Scala n00b (but am experienced with other languages) and am learning the language as I find time - very much enjoying it so far! Usually when learning a new language the first thing I do is implement Conway's Game of Life, since it's just complex enough to give a good sense of the language, but small enough in sco...

What frameworks to use to bootstrap my first production scala project ?

I am making my first foray into scala for a production app. The app is currently packaged as a war file. My plan is to create a jar file of the scala compiled artifacts and add that into the lib folder for the war file. My enhancement is a mysql-backed app exposed via Jersey & will be integrated with a 3rd party site via HttpClient inv...

Scala class to implement two Java Interfaces - how?

Hi, I have just started learning Scala and I'm now wondering how I could implement two different Java interfaces with one Scala class? Let's say I have the following interfaces written in Java public interface EventRecorder { public void abstract record(Event event); } public interface TransactionCapable { public void abstrac...

Scala method where type of second parameter equals part of generic type from first parameter

I want to create a specific generic method in Scala. It takes two parameters. The first is of the type of a generic Java Interface (it's from the JPA criteria query). It currently looks like this: def genericFind(attribute:SingularAttribute[Person, _], value:Object) { ... } // The Java Interface which is the type of the first paramet...

Trait, FunctionN, or trait-inheriting-FunctionN in Scala?

I have a trait in Scala that has a single method. Call it Computable and the single method is compute(input: Int): Int. I can't figure out whether I should Leave it as a standalone trait with a single method. Inherit from (Int => Int) and rename "compute" to "apply." Just get rid of Computable and use (Int => Int). A factor in favo...

Estimate serialization size of objects?

In my thesis, I woud like to enhance messaging in a cluster. It's important to log runtime information about how big a message is (should I prefer processing local or remote). I could just find frameworks about estimating the object memory size based on java instrumentation. I've tested classmexer, which didn't come close to the serial...

Other programming languages that support implicits "a la Scala"

Hi. Scala implicits are very powerfull. I'm curious if they are a new/unique feature of Scala, or the concept already existed in other programming languages. Thanks. EDIT: To clarify my question, yes, I'm talking about this concrete implementation. Having "implicit things" all around seemed strange at first, but having used it for a...

Tied up with injection implemented with setter functions

Hi, I'm trying to use Scala as part of an existing Java application and now I run into an issue with dependencies injected with a setter method (no DI frameworks in this part of code). How is this handled in a Scala way? In Scala both val and var require to be initialized when declared but I can't do that, since the Java setters injec...

Implicit conversion to Runnable?

As an exercise I tried to create an implicit conversion that would accept a function and produce a Runnable. That way you could call java methods that accept Runnables and use them like closures. the implicit conversion is easy enough: implicit def funToRunnable(fun : Unit) = new Runnable() { def run = fun } however I don't know ...

Scala: How do I convert a Map[Int, Any] to a SortedMap? Or a TreeMap?

I would like to convert a Map[Int, Any] to a SortedMap or a TreeMap and haven't been able to find an easy way to do it. ...

How to stop IntelliJ Scala plugin indenting blocks

On IntelliJ 9.0.2 with the latest Scala plugin, the problem is that the code formatter turns this: object Test { def main (args: Array[String]) { if (...) { ... } } } into this: object Test { def main (args: Array[String]) { if (...) { ... ...

Scala, importing class

I have two files: logic.scala and main.scala logic.scala contains one class and main.scala have one class with method main (to run it). And i wannt to import class from logic.scala and use this class to create object(s) and work with them. How to import and compile it in proper way? ...

How can I connect to a MySQL database using Scala?

I'm working on a little project where I'd like to parse some data, and then put it into a database. I'm not working with Lift, and I haven't been able to find a standard way to do this. I'm fine writing the queries myself, but I'm not sure what to use to actually connect to the DB. ...