Calling the !! method from one actor to another worker actor appears to keep the channel open even after the reply was received by the caller (ie: future is ready).
For example, using !! to send 11 different messages from one actor to another worker actor will result in 11 messages similar to the below being shown in the mailbox of the ...
For log tracing inside a for comprehension, I've used dummy assignment like this:
val ll = List(List(1,2),List(1))
for {
outer <- ll
a = Console.println(outer) // dummy assignment makes it compile
inner <- outer
} yield inner
The a = bit seems awkward. Is there a cleaner way?
...
What is the Scala's way to write the following code:
int i;
switch(i) {
case 1:
a();
break;
case 2:
case 15:
b();
c();
break;
default: foo()
}
I.e. what is the idiomatic way of executing the same piece of code based on multiple case values?
i match {
case 1 ...
How do I create an x(ht)ml-Node containing a href-attribute including a query string without the &s being escaped automatically or runtime error?
val text = Text("?key=val&key2=val2")
will be escaped and
val node = <a href="link?key=val&key2=val2">link</a>
throws (in Scala 2.7.5):
java.lang.AssertionError
The node will be used w...
Trying to define an accessor method for default constructor parameter, i.e.:
class Person (age: Int) {
def age: Int = this.age
}
Which obviously results in a compiler error: ambiguous reference to overloaded definition, both method age in class Person of type => Int and value age in class Person of type Int match expected type In...
I have a Java class that logs stuff which has a method like this:
void info(Object message, Object... params);
In Scala, I've created a wrapper around such call that looks like this:
def info(msg: => String, params: Any*) {
log.info(msg, params);
}
When I call:
val host = "127.0.0.1"
val port = "1234"
info("Start on {0}:{1}", ho...
I usually end up trying every combination until it compiles. Can somebody explain what I should use where?
...
trait NotNull {}
I've been trying to see how this trait can guarantee that something is not null and I can't figure it out:
def main(args: Array[String]) {
val i = List(1, 2)
foo(i) //(*)
}
def foo(a: Any) = println(a.hashCode)
def foo(@NotNull a: Any) = println(a.hashCode) //compile error: trait NotNull is abstract
def foo(a:...
I've tried two ways to constrain a generic type parameter to a nullable type, but both seem to have some unexpected problems.
First attempt (using T <: AnyRef):
scala> def testAnyRefConstraint[T <: AnyRef](option:Option[T]):T = {
| //without the cast, fails with compiler error:
| // "found: Null(null) required: T"
| o...
Greetings,
Learning Scala currently (2.7.7) and needed to reverse a Map to do some reverse value->key lookups. I was looking for a simple way to do this, but came up with only:
(Map() ++ origMap.map(kvp=>(kvp._2->kvp._1)))
Anybody have a more elegant approach?
...
'map' preserves the number of elements, so using it on a Tuple seems sensible.
My attempts so far:
scala> (3,4).map(_*2)
error: value map is not a member of (Int, Int)
(3,4).map(_*2)
^
scala> (3,4).productIterator.map(_*2)
error: value * is not a member of Any
(3,4).productIterator.map(_*2)
...
I just stumbled on one of Tony Morris' blog-posts about Java and a fundamental problem with the language: that of defining a bespoke equality-relation for a collection. This is something that I think is a big deal and wondered whether there was some scala solution.
The classic issue manifests itself in thinking about, say, a trade. Let...
Trying to understand the Scala quick sort example from Wikipedia. I wonder if anyone could disassemble the sample step by step and give explanation to all the syntactic sugar involved?
Apologies if the question makes me appear lazy, but I'm sure the effort will be appreciated by many other Scala newbies.
def qsort: List[Int] => List[I...
I'm a senior engineer working in a team of four others on a home-grown
content management application that drives a large US pro sports web
site. We have embarked upon this project some two years ago and chose
Java as our platform, though my question is not Java-specific. Since
we started, there has been some churn in our ranks. Each one...
Hello I am having problems when using the Scala Swing library in version 2.8 Beta1-prerelease. I have a situation where I want to show a table in GUI, and update it as results are returned from a SQL request. Which way could this be done in Scala, at the moment i am using the DefaultTableModel from Java library.
Another thing is that I ...
What is Scala equivalent of Java's static block ?
...
Hi SO members,
What Tools do you people use to work with Scala? For my learning phase, I used the Scala REPL and hacked some code with TextMate and compiled it with the scalac CLI. But as the projects grow in size, much more sophisticated tools are required.
I am aware of the Scala plugins for Elipse, IntelliJ and Netbeans and I tried ...
I'm learning Scala and was curious if it would be possible to:
Create an object which implements a Java interface in Scala
Compile the object into a class file and jar it
Use the object from Java
I want to implement a custom lucene query parser in scala and be able to let others access it from a java application.
...
I have recently been looking around to learn a new language during my spare time and Scala seems to be very attractive.
I have a few questions regarding it:
Will not knowing Java impose a
challange in learning it? Will it be
a big disadvantage
later on? ( i.e How often do people rely on
Java-specific libraries? )
How big of a differe...
Why do i get an error when I try using _ instead of using a named identifier?
scala> res0
res25: List[Int] = List(1, 2, 3, 4, 5)
scala> res0.map(_=>"item "+_.toString)
<console>:6: error: missing parameter type for expanded function ((x$2) => "item
".$plus(x$2.toString))
res0.map(_=>"item "+_.toString)
...