scala

App-engine and Scala

Hello, all. I have a 2-part question: Could you use Scala with Google's App Engine instead of Java? (Assuming 1 is answered yes) Would it be advised? Thanks ...

javadoc: show also descriptions of methods from parent class

Is there a way to produce javadoc so that all methods accessible from the class are listed with their full description? Usually only the methods defined in that class are listed and the rest are only linked to in "methods inherited from" section. (Obviously it is tricky to show javadoc of super classes if they're thirdparty and there's...

How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I obtained a nested list that I can't apply flatten to because it says: no implicit argument matching parameter type. How can I solve this? should...

Scala: defining main method that can be used by 'java'

The usual way of defining main in Scala (as shown below) can be used to run classes with 'scala', but not 'java' (since the created method is not static). How do I write a Scala class/object that can be executed with 'java'? object HelloWorld { def main(args: Array[String]) { println("Hello, world!") } } ...

Lift CometActor: Organizing HTML generated by render and fixedRender

I'm trying to build a simple search application as an learning experiment with Comet and the Lift Framework. The plan is to have a page with a text entry and space for search results. When a search term is entered, it should be transmitted as an ajax request and the results should be pushed back by the server and rendered on the same pag...

Scala: Something like Option (Some, None) but with three states: Some, None, Unknown

I need to return values, and when someone asks for a value, tell them one of three things: Here is the value There is no value We have no information on this value (unknown) case 2 is subtly different than case 3. Example: val radio = car.radioType we know the value: return the radio type, say "pioneer" b. there is no value: re...

Implementing a string class that does case insensitive comparisions in Scala

I've got a number of classes with fields that are meant to be case insensitive, and I'd like to put the instances of these classes into HashMaps and look them up by string case insensitive. Instead of using toLowerCase every time I want to index an instance by its string, or look up an instance by its string, I've instead tried encapsul...

Could/should an implicit conversion from T to Option[T] be added/created in Scala?

Is this an opportunity to make things a bit more efficient (for the prorammer): I find it gets a bit tiresome having to wrap things in Some, e.g. Some(5). What about something like this: implicit def T2OptionT( x : T) : Option[T] = if ( x == null ) None else Some(x) ...

How to subclass an object with a var in its primary constructor

I'm wanting to do something like this: class A (var updateCount: Int) { } class B (val name: String, var updateCount: Int) extends A(updateCount) { def inc(): Unit = { updateCount = updateCount + 1 } } var b = new B("a", 10) println(b.name) println(b.updateCount) b.updateCount = 9999 b.inc println(b.updateCount) but the com...

scala specs don't exit when testing actors

I'm trying to test some actors using scala specs. I run the test in IDEA or Maven (as junit) and it does not exit. Looking at the code, my test finished, but some internal threads (scheduler) are hanging around. How can I make the test finish? ...

Is there a problem-free way to run Scala 2.7.7 unit tests in Eclipse integrated nicely?

I'm developing Scala code using Eclipse, often when I run tests I get this error: No tests found with test runner 'JUnit 3'. Environment: Eclipse for Java Developers, 3.5.1 Scala 2.7.7 JUnit 4.7 I'm currently writing my tests as JUnit3 tests, and invoking them by right clicking on a package in the project explorer, choosing Run As ...

Is pretty XStream serialization feasible with Scala?

I'm trying out XStream as a way to quickly serialize objects to Xml or JSON to send over the wire, and deserialize. I do want the XML/JSON to be simple/clean. It seems to work well, I've added a few aliases, but now I've hit a problem, this code: println(new XStream.toXML(List(1,2,3))) produces this XML: <scala.coloncolon serializa...

Concurrent map/foreach in scala

I have an iteration vals: Iterable[T] and a long-running function without any relevant side effects: f: (T => Unit). Right now this is applied to vals in the obvious way: vals.foreach(f) I would like the calls to f to be done concurrently (within reasonable limits). Is there an obvious function somewhere in the Scala base library? Some...

How can I serialize (and later deserialize) a generic type in Scala?

Say I'd like to implement something like this: def serialize( list: List[_] ) : Node = { <list> { for ( item <- list ) yield serializeItem(item) } </list> } def deserialize( node : Node ) : List[_] = { // ? } How do I get the type of the List, e.g. T in List[T] so I can write that out? Or do I need it? How can I instantiate ...

How can I get XStream to output Scala lists nicely? Can I write a custom converter?

This code: println(new XStream.toXML(List(1,2,3))) produces this XML: <scala.coloncolon serialization="custom"> <unserializable-parents/> <scala.coloncolon> <int>1</int> <int>2</int> <int>3</int> <scala.ListSerializeEnd/> </scala.coloncolon> </scala.coloncolon> Instead I'd like this: <list> <int>1</int> <...

scala: anything like python/ruby development mode?

What I mean by the title is, whether there's a free framework/tool that allows me to write .scala files and have them reloaded & compiled automatically by the (web) server without the need to compile, package and deploy. Probably javarebel can be used here, but it is not free. ...

Scala difference between object and class

Greetings, I'm just going over some scala tutorials on the net and have noticed in some examples an object is declared at the start of the example. Can anyone explain to me what the difference between class and object are as far as scala is concerned? ...

How to resolve java.nio.charset.UnmappableCharacterException in Scala 2.8.0?

I'm using Scala 2.8.0 and trying to read pipe delimited file like in code snipped below: object Main { def main(args: Array[String]) :Unit = { if (args.length > 0) { val lines = scala.io.Source.fromPath("QUICK!LRU-2009-11-15.psv") for (line <-lines) print(line) } } } Here's the error: Exception in thread...

Approaching Text Parsing in Scala

I'm making an application that will parse commands in Scala. An example of a command would be: todo get milk for friday So the plan is to have a pretty smart parser break the line apart and recognize the command part and the fact that there is a reference to time in the string. In general I need to make a tokenizer in Scala. So I'm w...

Why doesn't Scala Source close the underlying InputStream?

I'm using Scala Source.fromFile however I can't seem to find a nice way of getting it to close the underlying InputStream once the file has been read. Here's my code that will fail with an AssertionError because the file cannot be deleted. def main(args : Array[String]) : Unit = { val myFile = new File("c:/tmp/doodah.txt") v...