scala

Scala Immutable MultiMap

In Scala I would like to be able to write val petMap = ImmutableMultiMap(Alice->Cat, Bob->Dog, Alice->Hamster) The underlying Map[Owner,Set[Pet]] should have both Map and Set immutable. Here's a first draft for ImmutibleMultiMap with companion object: import collection.{mutable,immutable} class ImmutableMultiMap[K,V] extends immutab...

Is a type-safe respond_to in scala possible?

Using a case construct for type-safe casting is easily done in scala. The following code ensures that square gets only called on objects which have an according type. class O class A extends O { def square(i: Int):Int = { i*i } } class B extends O { def square(d: Double):Double = { d*d } } class C extends O {} def square(o: O) ...

Ant task for compiling GUI forms (Intellij IDEA)

How I can create a Ant task to compile GUI forms (XML) in Intellij IDEA? I use Scala and Java in my project. Java only for GUI class, and I create it with Intellij IDEA UI Designer. ...

Is there anything like rubygems.org for scala libraries.

I notice there is an sbaz tool that seems to have similar functionality to the ruby gem tool but I don't see any community site like gemcutter.org / rubygems.org. Is there something like this around. There are 1084 repositories on github with scala in them. I'm surprised I can't find some centralized package management utility. Perhaps...

Comparison of Groovy and Scala against Java

I have recently come across the languages Groovy and Scala which are built on the JVM. But I dont know much beyond that. Are those languages going to overtake Java at some point? Do these languages serve for any special purpose? Which of them is faster and more powerful? For what type of applications should I choose Groovy/Scala? Will it...

How to bring simple name into scope?

I'm developing a code generator that will output the following classes/objects: class A { var a : Int = _ var b : B = _ class B { var b : Int = _ var c : C = _ class C { var c : Int = _ } } } object A { val a = ... object B extends Base { val b = ... object C extends Base { val c = ....

How do I use a @serializable scala object?

I know that you can mark a scala object as @serializable, but I don't understand what to do with the object afterwards. Do I simply treat it as a Java Serializable object? I want to serialize the object into a stream of bytes. Can someone show me the code to transform a serialize object into either a byte array or a string? (the goog...

Can you override the stream writers in scala @serializable objects?

I now understand that scala @serializable objects can be used the same as a Java Serializable object. In a Java Serializable object there are methods you can override to change how the object streams: writeObject(ObjectOutputStream) / readObject(ObjectOutputStream). Can you override or inject methods into a scala @serializable object ...

How to port Scala 2.7.7 code that uses scala.collection.jcl to Scala 2.8?

I've got some code that references scala.collection.jcl written against Scala 2.7.7. I'm now trying to compile it against Scala 2.8 for the first time, and I'm getting this error: "value jcl is not a member of package collection". Is there a substitute/replacement for jcl in 2.8? ...

Porting new Iterable{} code from Scala 2.7.7 to 2.8

I saw this thread: http://stackoverflow.com/questions/1243794/what-are-the-biggest-differences-between-scala-2-8-and-scala-2-7 It seems to cover some changes, but the first compile problems I've hit don't seem to be mentioned. Any suggestions? kinds of the type arguments (Iterable[Any] with (A with Int) => Any) do not conform to the...

Convertion of Scala typed collection to Java with an unbounded wildcard, etc. Collection<?>

Problem: Need to implement interface from 3rd party Java library in Scala ... Collection<?> getItemPropertyIds() ... My solution is to use ...<here goes Iterable>.asInstanceOf[java.util.Collection[_]] val props:Map[Object,Property] = ... override def getItemPropertyIds()=props.keys.asInstanceOf[java.util.Collection[_]] Is t...

Images in Eclipse

I am creating a Scala Project in Eclipse. It is just a simple Swing application. I tried to load an icon for my Frame window. iconImage = java.awt.Toolkit.getDefaultToolkit.getImage(resourceFromClassloader("icon.png")) I know there are src and bin folders in the project folder I created. I managed to load the icon.png if I put it in t...

val and object inside a scala class?

What is the difference between declaring a field as val, lazy val and object inside a scala class, as in the following snippet: class A class B { val a1 = new A { def foo = 1 } object a2 extends A { def foo = 1 } lazy val a3 = new A { def foo = 1 } } ...

"is not a member of package" error when importing package in Scala with SBT

(Relative beginner here, please be gentle...) I've got a Scala program that I can build with sbt. I can (from within sbt) run compile and test-compile with no errors. I've defined a package by putting package com.mycompany.mypackagename at the top of several .scala files. When I do console to get a Scala REPL, this happens: scala> impo...

Scala: Defining test cases based on folder

I have to test a program which takes one input file. I have put all the input files inside a folder and now I want to use SBT and ScalaTest to have following features: TestAll : Invoke the program with one input file at a time for all files Test one: Invoke the program with one input file provided as argument to test command from sbt c...

How do I get (a, b) => c from a => b => c in Scala?

If I have: val f : A => B => C This is shorthand for: val f : Function1[A, Function1[B, C]] How do I get a function g with the signature: val g : (A, B) => C = error("todo") (i.e.) val g : Function2[A, B, C] //or possibly val g : Function1[(A, B), C] in terms of f? ...

Why is currying and uncurrying not implicit in scala

If I have a function: f : A => B => C I can define an implicit conversion such that this can be used where a function (A, B) => C is expected. This goes in the other direction also. Why are these conversions not implicit (or available implicitly)? I am assuming that bad things could happen for some value of bad things. What value is ...

How to create the Scaladoc for a Maven+Scala 2.8+Java-Project with Scaladoc 2

The question says it all. I couldn't find an example on the web how to use the Scaladoc 2, especially on a Maven Project. I'm using Maven, Scala 2.8 and some Java classes, and the Maven Scala Plugin to build the project. But as it seems i cannot use the Maven Scala Plugin (where i could run mvn scala:doc) to create the docs because it ...

BufferedImage imageType in swing

I'm writing a widget that does some caching to avoid unecessary calls to Shape.draw on a bunch of shapes at every repaint. I've tried to do something like this (scala code): private val buffer = new BufferedImage(width, height, /* (1) */) ... override def paintComponent(Graphics2D g) = { if (hasChanged) { val bg = buffer.getGrap...

Appending a label to immutable case classes in Scala

Im trying to create a parser for a small language with commands including labels and goto: ... lazy val cmds = opt("{")~>rep(cmd<~opt(";"))<~opt("}") ^^ {...} lazy val cmd = ("if"~boolexpr~"then"~cmds~"else"~cmds ^^ { case _~b~_~c1~_~c2 => IFCMD(boolexpr,c1 | ident ~":="~numericLit ^^ {case i1~_~v => ASSIGN(i1,v) } | "goto" ~>ide...