Lets say I have
trait fooTrait[T] {
def fooFn(x: T, y: T) : T
}
I want to enable users to quickly declare new instances of fooTrait with their own defined bodies for fooFn. Ideally, I'd want something like
val myFoo : fooTrait[T] = newFoo((x:T, y:T) => x+y)
to work. However, I can't just do
def newFoo[T](f: (x:T, y:T) => T) =...
I've done some programming in Scala, and I know that, e.g.,
xs map f
is the same thing as
xs.map(f)
but I have no idea how to generalize this syntax to something like ScalaTest's syntax, e.g.,
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[String]
evaluating { emptyStack.po...
I have a scala actor that does some work whenever a client requests it. When, and only when no client is active, I would like the Actor to do some background processing.
What is the easiest way to do this? I can think of two approaches:
Spawn a new thread that times out and wakes up the actor periodically. A straight forward approach,...
I work on a fairly simple but large two-tier application that consists approximately 40 Eclipse RCP plugins. We have a new use case that is taking us to the web for a very small portion of this functionality. I'd like to prototype this using Lift. Clearly, I'm facing a few challenges.
Lift + OSGi. Can Lift get at OSGi bundles? Can...
I type these to the scala interpreter:
val a : Integer = 1;
val b : Integer = a + 1;
And I get the message:
<console>:5: error: type mismatch;
found : Int(1)
required: String
val b : Integer = a +1
^
Why? How can I solve this?
This time I need Integers due to Java interoperability reasons.
...
From reading parts of the Programming in Scala book, I realize that Scala can work with the Java Swing components to create GUI applications.
My question is if there are any projects or released applications (that are more than just simple examples) that use Scala and Swing?
...
Here are my goals:
1. Run my tests in Eclipse and see the pretty green or red bar.
2. Run my tests on the command line with a build tool.
I'm leaning towards specs and sbt, but I can't get them to work. I have no desire to pick up Maven. My question is which one of the follow sets works best?
sbt and scalatest
sbt and specs
ant and sc...
How to start external application from Scala?
...
Why index starts from 1 not from 0?
http://www.scala-lang.org/docu/files/api/scala/io/Source.html
...
For example, is it possible to have Scala, Java, and Clojure source all compile/build together properly inside the same project? Or, do I have to do them as separate project libraries then used by whatever I pick as the "master" project?
If neither of those, how's everyone else doing it?
...
Can anyone recommend a good 2D animation package for Scala? I prefer something which already have some basic events handling, more like JavaFX than like processing.org.
...
I am studying JavaFX Script and trying to compare it to Scala, which is another very interesting new language for the Java platform.
In the official Scala site I found this example, which is a Quick Sort implementation.
I then wrote the following equivalent JavaFX Script program (using NetBeans IDE 6.7.1):
package examples;
function s...
The scala.xml package represents XML with nodes of a labelled tree. But is this tree unidirectional in Scala 2.7, as there seems to be no way to access the Elem parent of a given Elem? The same seems to apply for parent Document. For example, in XOM you have getParent and getDocument accessors to navigate towards the root of the tree. Ca...
In Scala, you can overload a method by having methods that share a common name, but which either have different arities or different parameter types. I was wondering why this wasn't also extended to the return type of a method? Consider the following code:
class C {
def m: Int = 42
def m: String = "forty two"
}
val c = new C
val...
Hi.
Is there an IDE/Tool/script/something that can show call hierarchy and/or data flow in Scala+Java programs (preferably from source code).
Or (as a backup plan) is there a tool that can show it using Java bytecode? (And preferably give the option to go to source code, if provided by user).
All that, preferably integrated into an IDE a...
Is it possible to match on a comparison using the pattern matching system in Scala?
For example:
a match {
case 10 => println("ten")
case _ > 10 => println("greater than ten")
case _ => println("less than ten")
}
The second case statement is illegal, but I would like to be able to specify "when a is greater than".
...
Well, I'm learning Scala so this question may be too basic for most people.
In Java I can have a static slot (function or variable) in a class, and then I will have that slot in inherited classes too.
In Scala I don't have static slots, but I have companion objects. But I'm finding out that those objects are not part of the inherited c...
I'm learning Scala and there is a thing that I can't find out about the language:
Some time ago I was very comfortable programming in Lisaac, and in Lisaac I could write a class PERSON with a slot list:ARRAY[SELF], which was equivalent to have list:ARRAY[PERSON], since SELF is the type of the object where that slot is.
But by using SEL...
I'm learning scala and can't find out how to do this:
I'm doing a mapper between scala objects and google appengine entities, so if i have a class like this:
class Student {
var id:Long
var name:String
}
I need to create an instance of that class, in java i would get the Field by it's name and then do field.set(object, value)...
How do I declare a generic variable in Scala without initializing it (or initializing to any value)?
def foo[T] {
var t: T = ???? // tried _, null
t
}
...