scala

Scala wants from me apply method

import java.util.Random class Kostka { val rand = new Random(System.currentTimeMillis()) val value: List[Int] = List(rand.nextInt(6+1)) } object MyRandom { def Fill[A](n: Int): List[A] = { if (n<=0) Nil else { var lst = List[A] for (i <- 1 to n){ lst ++= (new Kostka).val...

How do I set a system property for my project in sbt?

I'm sure I'm missing something really simple... I want to set the system property java.awt.headless to true for my sbt project. Reading the page on properties I think that I need to use system or systemOptional. In my project file I've tried things like: lazy val javaAwtHeadless = system[Boolean]("java.awt.headless") Setting it as a u...

Rendering (streaming) HTML into Pane

My program generates results concurrently. I want to append each result, as soon as it enters the swing-thread, to a pane which shall render the result's html-fragment like: <ol class="result-type-a"><li class="foo-result"><html-output-of-result .../></li></ol> Is the JTextPane the right component? Are there problems with my "streami...

When is a return type required for methods in Scala?

The Scala compiler can often infer return types for methods, but there are some circumstances where it's required to specify the return type. Recursive methods, for example, require a return type to be specified. I notice that sometimes I get the error message "overloaded method (methodname) requires return type", but it's not a general...

convert java.util.Map[String, Object] to scala.collection.immutable.Map[String, Any]

How do I convert java.util.Map[String, Object] to scala.collection.immutable.Map[String, Any], so that all values in the original map (integers, booleans etc.) are converted to the right value to work well in Scala. ...

how to build this navigation in liftweb(scala languange)?

the code is: val nav = Menu(Loc("Home",List("index"),"home")) :: Menu(Loc("Daily",List("daily"),"daily")) :: Menu(Loc("Photo",List("photo"),"photo")) ::Nil` hi,I an newer in scala and liftweb but i troubled when i built navigation in snippet help me please ...

Elegant way to reverse a list using foldRight?

I was reading about fold techniques in Programming in Scala book and came across this snippet: def reverseLeft[T](xs:List[T]) = (List[T]() /: xs) { (y,ys) => ys :: y } As you can see, it was done using foldLeft or /: operator. Curious how it would look like if I did it using :\, I came up with this: def reverseRight[T](xs:List[T]...

Parametric type + function requires a string as second parameter?

class TestClass[T](val x: T) { def +(other: TestClass[T]) = x + other.x } this definition gives me the following compile error: error: type mismatch; found : T required: String def +(other: TestClass[T]) = x + other.x is it not possible to use Int or Double as a type parameter and use addition in Scala?? ...

Algorithm mixing

I have a class that extends Iterator and model an complex algorithm (MyAlgorithm1). Thus, the algorithm can advance step by step through the Next method. class MyAlgorithm1(val c:Set) extends Iterator[Step] { override def next():Step { /* ... */ } /* ... */ } Now I want apply a different algorithm (MyAlgorithm2) in eac...

Scala - are classes sufficient?

Coming from Java I am confused by the class/object distinction of scala. Note that I do not ask for the formal difference; there are enough references on the web which explain this, and there are related questions on SO. My questions are: Why did the designers of scala choosed to make things more complicated (compared to Java or C#)...

In Scala, how would I give a Singleton a constructor?

My design incorporates a small database abstraction, whereby I implement each database as a Singleton (well, an object), with custom methods on the database for the couple of operations the code calls (it's mainly a log parser, dumping interesting statistics to a database). I'd like to construct the Singleton database classes if possibl...

Scala 2.8.0 toolchain

I've currently spent the best part of my day grappling with dependency hell; something I haven't really experienced in a while. I'm attempting to use Scala 2.8.0 as per the answers to this question, and the fact that I intend to use Actors - for which the fork/join pool seems to be faster (according to community buzz, anyhow). The prob...

How to get Long/Int value of a enum set in Scala 2.8

In Scala 2.7, Enumeration provide Set32/Set64 to build enum set and easily get the bitwise value in Long/Int or build enum set back from a Long/Int value (which ease db storage). Scala 2.8 removed these classes. Is there a replacement in 2.8 lib? ...

sbt: restarting a process on a code change

Using the ~run command, the simple build tool will re-run an executable target for me whenever a source file changes. This is nice, but if the target is a long-running server process, sbt is suspended until the child terminates, so source changes have no effect. I'd like to have sbt monitor and recompile my sources even while the tar...

infer a common supertype based on a parameter value and function parameter types

Should the following be compiled without needing an explicit type definition on this? def prepList[B >: A](prefix: PlayList[B]) : PlayList[B] = prefix.foldr(this: PlayList[B])((node, suffix) => suffix.prepNode(node)) It seems to me that the type should be able to inferred. Is this just a limitation in the Scala compiler, or is there...

Lift filter to force ssl

Hi, in a struts application, I have a filter that forces certain pages to be accessed only over https via redirection. I'm thinking in porting it to lift so my question is: In the this environment, is there a "lift" way to implement such filter or is it similar/the same as in struts ? Thanks ...

Responding to key events in scala

Hi chaps, I'm experimenting with a bit of Scala gui programming (my first project in scala, so I thought I'd start with something simple). But I seem to have got stuck at something that seems like it should be relatively trivial. I have a class that extends scala.swing.MainFrame, and I'd like to detect when a user presses a key when that...

How do I sort a collection of Lists in lexicographic order in Scala?

If A has the Ordered[A] trait, I'd like to be able to have code that works like this val collection: List[List[A]] = ... // construct a list of lists of As val sorted = collection sort { _ < _ } and get something where the lists have been sorted in lexicographic order. Of course, just because A has the trait Ordered[A] doesn't mean th...

Use Scala as if it was Java

I've been reading up on Scala a lot recently and I really want to get into it. I do my Java web development from within Eclipse with Tomcat as my preferred server and I'd like to keep it that way. I've tried the Scala Eclipse plugin but it's safe to say, it isn't there yet. I had to uninstall it because it simply ins't working. On top of...

HowTo get the class of _ :Any

I've wrapped a Message and would like to log which message I've wrapped. val any :Any = msg.wrappedMsg var result :Class[_] = null The only solution I could find is matching everything: result = any match { case x:AnyRef => x.getClass case _:Double => classOf[Double] case _:Float => classOf[Float] case _:Long => classOf[Lo...