scala

Is there any game engine in Scala?

I wonder if there are any game engine written in Scala or easily accesible from Scala? ...

How to set an expected exception using Scala and JUnit 4

I want to set an expected exception for a JUnit 4 test using Scala. I am current doing something similar to the following: @Test(expected=classOf[NullPointerException]) def someTest() = { // Some test code } But I get the following compiler error: error: wrong number of arguments for constructor Test: ()org.junit.Test ...

Can someone explain Scala's yield?

I understand Ruby and Python's yield. What does Scala's yield do? ...

Functional Reactive Programming in Scala

Are there any libraries written for Scala enabling Functional Reactive Programming? ...

Converting Enumeration to Iterator

I have the following implicit conversion for java.util.Enumerations implicit def enumerationIterator[A](e : Enumeration[A]) : Iterator[A] = { new Iterator[A] { def hasNext = e.hasMoreElements def next = e.nextElement def remove = throw new UnsupportedOperationException() } } Unfortunately it doe...

Is it bad practice to send an actor a message from something which is not an actor?

Suppose I have some class which has a property actor_ of type Actor. Is there a problem with me doing def someMethod() = { actor_ ! "HELLO" } Or should sending a message always be done from another actor; e.g. def someMethod() = { Actor.actor { actor_ ! "HELLO" } } ...

How can I identify a remote actor?

I have a remote actor (client) which is registering with another remote actor (server) and then later deregistering (with a shutdown hook). However, although the server picks up the de-registration, the actual sender property is a different Channel object; so in my server logs I have: Registered new client [scala.actors.Channel@158e2...

What does the remote-actor framework do if trying to write to a client which is no longer there?

I have a server which is using the remote actors framework to communicate with multiple clients. As mentioned in this question, I am having trouble keeping track of when a client disappears. Hence my server is still attempting to send messages to non-existent clients. Is this a problem? (I don't see any exceptions being thrown - but I ...

How is Scala "filling in" missing arguments to a case class?

When I call: actor_ ! Exit How is this being converted into a construction of: case class Exit(from: AbstractActor, reason: AnyRef) In particular, how is it that when I call this from a remote (client) actor which has been linked to a remote (server) actor, that the server receives an instance of Exit where the from property is an ...

How is this case class match pattern working?

I've just seen this case class in the Scala actors package: case class ! [a](ch: Channel[a], msg: a) And in the JavaDoc it describes usage in the following form: receive { case Chan1 ! msg1 => ... case Chan2 ! msg2 => ... } Why is this not: receive { case !(Chan1, msg1) => ... case !(Chan2, msg2) => ... } Is the bang ope...

scala Iterable#map vs. Iterable#flatMap

What is the difference between the map and flatMap functions of Iterable? ...

Scala/Lift question rss feed fetch

I'm looking for a simple line or two of code that will grab an rss feed like this php line: $feed = "URL" from within a scala object. I'm using scala/lift with Netbeans or Eclipse if it's relevant ...

What is the purpose of Scala language?

It is my opinion that every language was created for a specific purpose. What was Scala created for and what problems does it best solve? ...

Static inner classes in scala

What is the analog in Scala of doing this in Java: public class Outer { private Inner inner; public static class Inner { } public Inner getInner() { return inner; } } I specifically want my inner class to not have to have a fully qualified name - i.e. I want Trade.Type, not TradeType. So in Scala I imagined it might be somet...

Listing combinations WITH repetitions in Scala

Trying to learn a bit of Scala and ran into this problem. I found a solution for all combinations without repetions here and I somewhat understand the idea behind it but some of the syntax is messing me up. I also don't think the solution is appropriate for a case WITH repetitions. I was wondering if anyone could suggest a bit of code th...

How can I convert a Java Iterable to a Scala Iterable?

Is there an easy way to convert a java.lang.Iterable[_] to a Scala.Iterable[_] ? ...

Construct a java.util.List from a java.util.Set in Scala

I would like to create a java List based on another java Collection eg. Set in Scala. Why is this not possible? I get a required: scala.this.Int error. val in: java.util.Set[String] = new java.util.HashSet() val out : java.util.List[String] = new java.util.ArrayList(in) This worked however, but doesn't feel right: val in: java.util....

Scala: match and parse an integer string?

I'm looking for a way to matching a string that may contain an integer value. If so, parse it. I'd like to write code similar to the following: def getValue(s: String): Int = s match { case "inf" => Integer.MAX_VALUE case Int(x) => x case _ => throw ... } The goal is that if the string equals "inf", return In...

Question on Scala Closure (From "Programming in Scala")

I don't understand why authors said that Code Listing 9.1 from "Programming in Scala" use closure. In chapter 9, they show how to refactor code into more less duplicated form, from this original code: object FileMatcher { private def filesHere = (new java.io.File(".")).listFiles def filesEnding(query: String) = for (file <- file...

Mixing Multiple Traits in Scala

Quick Note: Examples from this tutorial. Suppose I have the following Traits: Student, Worker, Underpaid, Young How could I declare a class (not instance) CollegeStudent with all these traits? Note: I am aware of the simplests cases, such as CollegeStudent with one or two Traits: class CollegeStudent extends Student with Worker ...