I have seen this usage of Function.tupled example in another answer: Map(1 -> "one", 2 -> "two") map Function.tupled(_ -> _.length).
It works:
scala> Map(1 -> "one", 2 -> "two") map Function.tupled(_ -> _.length)
<console>:5: warning: method tupled in object Function is deprecated:
Use `f.tuple` instead
Map(1 -> "one", 2 -> "t...
What does scala @ operator do?
For example at
this page there is a something like this
case x @ Some(Nil) => x
...
The scala docs say that Enumeration.Val is ordered, however I get inconsistent behavior when when I try to enforce type restrictions on enumeration values requiring them to support ordering:
object Dogs extends Enumeration {
val Sam, Tom, Rover = Value
}
def doSomething[A <% Ordered[A]](a : List[A]) : Unit = {
println(a.sortWit...
This produces an anonymous function as expected (f is a function with three arguments):
f(_, _, _)
What I don't understand is why this doesn't compile, instead giving a "missing parameter type" error:
f(_, _, 27)
I need to specify the types of the underscores explicitly. Shouldn't Scala be able to infer their types given that the p...
I would like to add a method to scala.Enumeration. My first approach was to try to extend it, but was bitten by this. My second approach was to try to define a method, and pass in the Enumeration - if that worked, I hoped to use an implicit conversion. I'm having a hard time preserving type with the return type of the method, however....
Is it possible to use them in conjunction? It would be nice to write the GUI in JavaFX and define the business logic in Scala. Any ideas?
...
I want to rewrite in scala the example from Sun's tutorial about concurrency in java. The original code is here: http://java.sun.com/docs/books/tutorial/essential/concurrency/deadlock.html
This code is incorrect. It freezes at where the comment indicates. Could anyone correct this? Thanks in advance.
import scala.actors.Actor
class Pe...
I need to build a simple parser for a input type expressed as text.
I have implemented a FSM in Java using two int arrays:
states[][]
actions[][]
As I was debugging it I realized that it might be easier to use Java Enums as a variable of those types should show up as the value in the debug view in IntelliJ. However, when I started d...
I have been learning Scala for the past couple of months and now I feel I can start using into real work apart from solving some simple problems. My question here is how well do these two work together?
I have a couple of Java projects which I am working on now. How easy wiil it be to start using scala in them? Are there any gotchas to...
Just to clarify, when I say multiple assigment, parallel assignment, destructuring bind I mean the following pattern matching gem
scala> val (x,y) = Tuple2("one",1)
x: java.lang.String = one
y: Int = 1
which assigns "one" to x and 1 to y.
I was trying to do
val (x,y) = "a b".split()
I was expecting that scala would attempt to patt...
Hello everyone,
in Scala 2.8 how do I create an array of multiple dimensions? For example I want an integer or double matrix, something like double[][] in java.
I know for a fact that arrays have changed in 2.8 and that the old arrays are deprecated, but are there multiple ways to do it now and if yes, which is best?
Hoping for quick ...
I am creating a DSL, and using Scala's parser combinator library to parse the DSL. The DSL follows a simple, Ruby-like syntax. A source file can contain a series of blocks that look like this:
create_model do
at 0,0,0
end
Line endings are significant in the DSL, as they are effectively used as statement terminators.
I wrote a Scala...
This code does not compile:
object Token extends Enumeration {
type ID = Value
val Key, Value = Value
}
error: recursive value Value needs type
What should be done to have 'Value' in the enumeration ?
...
I am experimenting with parser combinators and I often run into what seems like infinite recursions. Here is the first one I ran into:
import util.parsing.combinator.Parsers
import util.parsing.input.CharSequenceReader
class CombinatorParserTest extends Parsers {
type Elem = Char
def notComma = elem("not comma", _ != ',')
def ...
Possible Duplicate:
Where do I find an Open Source project written in Scala?
I have been learning Scala for the past few weeks and I guess I am ready to get my hands dirty with some real meaningful project. But before actually starting a project and doing things wrong, I want to understand an existing opensource project done b...
I'm sure it should be obvious, but I could find any references on my question.
What underlying technology does Scala XML uses? Is it something DOM-like or SAX-like or StAX like? What performance penalties should I be aware of when processing large documents? Is StAX still more efficient?
Thanks in advance.
...
i've defined 'using' keyword as following:
def using[A, B <: {def close(): Unit}] (closeable: B) (f: B => A): A =
try { f(closeable) } finally { closeable.close() }
i can use it like that:
using(new PrintWriter("sample.txt")){ out =>
out.println("hellow world!")
}
now i'm curious how to define 'using' keyword to take any number...
In Scala 2.8 is there a way to overload constructors of a case class?
If yes, please put a snippet to explain, if not, please explain why?
...
I want to create an Action to automate GCJ compilation. Since I couldn't make it work with Ant, I decided to try SBT. The docs say how to create an Action and how to run an external process. What I don't yet see is how to reuse the directory tree traversal which exists for java and scala compiler Actions. In this case my input files woul...
Basically, I would like to be able to build a custom extractor without having to store it in a variable prior to using it.
This isn't a real example of how I would use it, it would more likely be used in the case of a regular expression or some other string pattern like construct, but hopefully it explains what I'm looking for:
def som...