There are some "global" functions in scala, for example:
print
println
classOf
format
The first 2 are actually Console's singleton methods, the last comes from java.lang.String.format.
I believe there are some more, may somebody list all of them, or point out where I can find corresponding API documentation ?
...
In Scala 2.8, calling groupBy() on a collection returns a Map where the values are collections, but I want a MultiMap. What's the easiest way to do the conversion? Can I avoid creating a new MultiMap and copying everything over?
...
How do I use case class matching with aliased types? This works when I pull CB etc out of Container.
class DoStuff[TKey](
val c : Container[TKey]#CB
)
{
type CB = Container[TKey]#CB
type C1 = Container[TKey]#C1
type C2 = Container[TKey]#C2
c match {
case C1(e1) => e1 // - not found: value e1 - not found: value C1
...
Is there a way to monitor how many threads are actually alive and running my scala actors ?
...
My language of choice is Ruby, but I know because of twitter that Ruby can't handle a lot of requests. It is a good idea using it for socket development? or Should I use a functional language like erlang or haskell or scala like twitter developers did?
...
How to explain Scala's type system to a Haskell expert?
What examples show Scala's advantages?
How to explain Haskell's type system to an advanced Scala practitioner?
What can be done in Haskell that can't be done in Scala?
...
I wondering if it's possible to get the MatchData generated from the matching regular expression in the grammar below.
object DateParser extends JavaTokenParsers {
....
val dateLiteral = """(\d{4}[-/])?(\d\d[-/])?(\d\d)""".r ^^ {
... get MatchData
}
}
One option of course is to perform the match again inside the ...
When trying to figure how a library works, implicit conversions are confusing. For example, looking at an expression like 'val foo: Foo = 1', what converts 1 to Foo?
Is it possible to instruct the scala library (or REPL) to print out the code paths that are executing while evaluating an expression?
...
I'm having trouble extending a base class that extends Ordered[Base]. My derived class can't extend Ordered[Derived] so can't be used as a key in a TreeMap. If I create a TreeMap[Base] and then just override compare in Derived that works but it's not what I want. I would like to be able to have the derived class as a key. Is there a way ...
I have created a class called CaseInsensitive which wraps a string (see http://stackoverflow.com/questions/1745910/implementing-a-string-class-that-does-case-insensitive-comparisions-in-scala).
I've created a case class which has a member variable of type CaseInsensitive, so it gets a default unapply method, which extracts a variable of...
What is the simplest method to remove the last character from the end of a String in Scala?
I find Rubys String class has some very useful methods like chop. I would have used "oddoneoutz".headOption in Scala, but it is depreciated. I don't want to get into the overly complex:
string.slice(0, string.length - 1)
Please someone tell me...
This is really strange to me and it's becoming into a real problem.
I'm building a site in appengine (java) using scala and It's working really slow when accessed from my domain:
/latest 200 1505ms 2325cpu_ms 1586api_cpu_ms 4kb
But when accessed from appspot it works much faster:
/latest 200 180ms 269cpu_ms 221api_cpu_ms 4kb
I've ...
For a java/scala project I have some dependencies that are not in a remote repository, but somewhere else in my filesystem. I have then two options, which lead to questions:
I can add a lib/ directory in my project folder. How can I tell buildr to add the content to the class path ?
I can use the builtin dependencies management system....
Is it possible to write a generalised orElse method from Option that takes a variable number of arguments? That is, instead of:
lazy val o1 = { println("foo"); None }
lazy val o2 = { println("bar"); Some("bar") }
lazy val o3 = { println("baz"); Some("baz") }
// ...
o1 orElse o2 orElse o3 // orElse ...
You could use:
orElse(o1, o2, o...
See: http://stackoverflow.com/questions/793415/use-of-anonymous-class-in-c
In C# you can write:
var e = new { ID = 5, Name= "Prashant" };
assertEquals( 5, e.ID )
But in Scala I end up writing:
var e = (5, "Prashant")
assertEquals( 5, e._1 )
Scala maintains type safety through the use of generics (as does C#), but loses the readabi...
I have a Map[Long, String] which I would like iterate over in descending order of the keys. The way I chose to do this was as follows:
var m: SortedMap[Long, String] = TreeMap.empty( (l: Long) => -l)
m ++= Map(2L -> "Hello", 1L -> "World", 3L -> "Chris")
println(m) //Map(3 -> Chris, 1 -> World, 2 -> Hello)
I'm really not sure I unders...
I came across the following statement in Trapexit, an Erlang community website:
Erlang is a programming language used
to build massively scalable soft
real-time systems with requirements on
high availability.
Also I recall reading somewhere that Twitter switched from Ruby to Scala to address scalability problem.
Hence, I won...
In scala I can write:
val pf: PartialFunction[String, Unit] = {case s => println(s)}
Now I can pass pf around, calling it with appropriate values.
I'm looking for a concise way of being able to define such a pf so that it can have a state. Say a counter of how many times it has been called. One way is this:
var counter = 0
val pf: ...
Given a function that takes a variable number of arguments, e.g.
def foo(os: String*) =
println(os.toList)
How can I pass a sequence of arguments to the function? I would like to write:
val args = Seq("hi", "there")
foo(args)
Obviously, this does not work.
...
I am writing my first large Scala program. In the Java equivalent, I have an enum that contains labels and tooltips for my UI controls:
public enum ControlText {
CANCEL_BUTTON("Cancel", "Cancel the changes and dismiss the dialog"),
OK_BUTTON("OK", "Save the changes and dismiss the dialog"),
// ...
;
private final String contr...