scala

How do I rewrite a for loop with a shared dependency using actors

We have some code which needs to run faster. Its already profiled so we would like to make use of multiple threads. Usually I would setup an in memory queue, and have a number of threads taking jobs of the queue and calculating the results. For the shared data I would use a ConcurrentHashMap or similar. I don't really want to go down th...

Force repaint after button click

consider this piece of scala swing code detail.reactions += { case ButtonClicked(but) => detail.contents += new Label(but.text) detail.background = new java.awt.Color(0,255,0) } the detail is of FlowPanel type. When the button is clicked, the color is instantly repainted, but the Label is not. It gets visible as I click the...

Create and populate two-dimensional array in Scala

What's the recommended way of creating a pre-populated two-dimensional array in Scala? I've got the following code: val map = for { x <- (1 to size).toList } yield for { y <- (1 to size).toList } yield (x, y) How do I make an array instead of list? Replacing .toList with .toArray doesn't compile. And is there a more co...

Accessing type members outside the class in Scala

Hi, I am trying to understand type members in Scala. I wrote a simple example that tries to explain my question. First, I created two classes for types: class BaseclassForTypes class OwnType extends BaseclassForTypes Then, I defined an abstract type member in trait and then defined the type member in a concerete class: trait ScalaT...

What is the proper way to remove elements from a scala mutable map using a predicate

How to do that without creating any new collections? Is there something better than this? val m = scala.collection.mutable.Map[String, Long]("1" -> 1, "2" -> 2, "3" -> 3, "4" -> 4) m.foreach(t => if (t._2 % 2 == 0) m.remove(t._1)) println(m) P.S. in Scala 2.8 ...

maven and lift using scala 2.8 : lift-mapper missing?

Newbie question since I'm not up to speed using maven at all. I'm trying to use scala + lift using scala 2.8, environment is a win7 box if that matters. I create a basic project using: mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=2.0-scala280-SNAPSHOT -Da...

Default type-parametrized function literal class parameter

Is this an intended behavior or is it a bug? Consider the following trait (be it a class, doesn't matter): trait P[T] { class Inner(val f: T => Unit = _ => println("nope")) } This is what I would have expected: scala> val p = new P[Int] { | val inner = new Inner | } p: java.lang.Object with P[Int]{def inner: this.In...

scala for yield setting a value

Hi, I want to create a list of GridBagPanel.Constraints. I read it in the scala programming book, that there is a cool for-yield construction, but I probably haven't understood the way it works correctly, because my code doesn't compile. Here it is: val d = for { i <- 0 until 4 j <- 0 until 4 } yi...

Overriding Scala Enumeration Value

As far as I can tell, Scala has definitions for the Enumeration Value class for Value(Int), Value(String), and Value(Int, String). Does anyone know of an example for creating a new Value subclass to support a different constructor? For example, If I want to create an Enumeration with Value(Int, String, String) objects, how would I do i...

NoSuchMethod exception when using scala Regex class... confused...

Hi there, I have a simple Scala project that runs without any problems inside Eclipse, however, when packaged into a .jar I receive this exception when running it: Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: scala.util.matching.Regex.replaceAllIn(Ljava/lang/CharSequence;Lscala/Function1;)Ljava/lang/String; What...

The Scala way to use one actor per socket connection

I am wondering how it is possible to avoid one socket connection pr. thread in Scala. I have thought a lot about it, but I always end up with some code which is listening for incoming data for each client connection. The problem is that I want to develop an application which should simultanously handle perhaps a couple of thousand conne...

Why "avoid method overloading" ?

Why does Jorge Ortiz advise to avoid method overloading? ...

are scala's mouse events working? how?

Hi, I'm trying to create link-like label in scala. But no mouse events works for me. How are they supposed to work? class Hyperlink extends Label{ text = "hyperlink" reactions += { case MouseClicked(_,_,_,_,_) => println("mouse clicked")}} I put this in some panel and click over the label like a pro minesweeper player... a...

Why scala's TreeSet returns SortedSet

Is there a reason that the object TreeSet.apply method returns SortedSet and not TreeSet? The following code won't compile in scala 2.7 val t:TreeSet[Int] = TreeSet(1,2,3) ...

Scala create List[Int]

Hi, How can I quickly create a List[Int] that has 1 to 100 in it? I tried List(0 to 100) , but it returns List[Range.Inclusive] Thanks ...

Scala Generic Function Values (Anonymous Function) - Missing Parameter Type (Error)

Hi all, im new with SCALA (Scala code runner version 2.7.7.final), and i really dont understand why scala requires for the caller the parameter type when we are using high order functions. The sample below , i have one stand alone object ( Util ) that have one function. The Main block, the caller must pass the parameter type to the ano...

Is there a existing way to generate surefire reports with simple-build-tool?

I'm working on a project using Scala running Selenium tests as part of a continuous integration process. Hudson displays very helpful information based on the results in the surefire reports but I would much prefer using sbt to Maven. Is there an existing way to get sbt to generate surefire reports from sbt tests? ...

Functional way to get a matrix from text

I'm trying to solve some Google Code Jam problems, where an input matrix is typically given in this form: 2 3 #matrix dimensions 1 2 3 4 5 6 7 8 9 # all 3 elements in the first row 2 3 4 5 6 7 8 9 0 # each element is composed of three integers where each element of the matrix is composed of, say, three integers. So this example should...

Difference between method and function in Scala

i read http://www.naildrivin5.com/scalatour/wiki_pages/ScalaFunctions. In that post he specified Methods and functions are not the same thing. But he didn't explain anything about it. can anyone explain what he was trying to say. ...

what is wrong: "value Parsers is not a member of package scala.util.parsing.combinator"?

I've got the above odd error message that I don't understand "value Parsers is not a member of package scala.util.parsing.combinator". I'm trying to learn Parser combinators by writing a C parser step by step. I started at token, so I have the classes: import util.parsing.combinator.JavaTokenParsers object CeeParser extends JavaTokenPa...