scala

Scala "<-" for comprehension

Hello guys, I have found that Scala always has a "natural explanation" to anything. Always something like "ohh, but that's just a function being called on this and that object with this and that parameter". In a sense, nothing is really compiler-magic as we know it from other languages. My question is on the <- operator as used in the ...

Scala: Create structure (XML) from Lists of Lists

I have a structure from java, a List < List < String > > containing elements like: [[ "Node0", "Node00", "Leaf0"], [ "Node0", "Node00", "Leaf1"], [ "Node1", "Leaf2"], [ "Node0", "Leaf3"], [ "Node2", "Node20", "Node200", "Leaf4"]] What I want to do is to create a XML structure (using Scala) in the most simple way, ending in somethi...

strange syntax in lambda expression

val (xa, xb) = xs partition ( a > ) What is a > in above code and how is it different from a > _? (assume a is some predefined value) ...

Scala Listener/Observer

Typically, in Java, when I've got an object who's providing some sort of notification to other objects, I'll employ the Listener/Observer pattern. Is there a more Scala-like way to do this? Should I be using this pattern in Scala, or is there something else baked into the language I should be taking advantage of? ...

scala types and inheritance misunderstanding

Hello, could you explain me what is incorrect in this trivial example? class C1 (val id: Int) abstract class C2 [T] { def m1 [T] } class C3 [C1] extends C2 { override def m1 (obj: C1) { println (obj.id) } } I have got: value id is not a member of type parameter C1 Why? ...

In Scala, is it possible to write a script which refers to another script.

Hey all, I am currently looking at using Scala scripts to control the life-cycle of a MySQL database instead of using MS-DOS scripts (I am on Windows XP). I want to have a configuration script which only holds configuration information, and 1 or more management scripts which use the configuration information to perform various operat...

Ensime doesn't show source code of downloaded libraries

I'm currently a happy user of emacs-ensime. Wholly it's a good IDE but there is an issue - I can't view scaladoc when I choose some method of a class in type inspector. I use ivy for dependency management, it downloads libs that I need with source code and doc jars (sometimes only with docs/sources). According to ensime manual it shoul...

Problem with creating java anonymous class with generics in scala

For example I have following Java inteface public interface Test<T,M> { public M get(T t); } if I whant create ananymoys class in java with this interface val t = new Test[Int,Boolean](){ def get(t: Boolean) = 0 } I have following error Scala.scala:15: error: scal.test.example.Test does not take type parameter...

Could not find implicit value for parameter ordering

Hi, I get the following error when trying to compile this: Btree.scala:9: error: could not find implicit value for parameter ordering: Ordering[K] abstract class Node[K,V] extends TreeMap[K,V] TreeMap is supposed to accept an implicit Ordering[A] val which I provide. Perhaps the implicit parameter needs to be in object Tester ...

Scala class members and constructor parameters name clash

Hi. Consider the following class written in Java: class NonNegativeDouble { private final double value; public NonNegativeDouble(double value) { this.value = Math.abs(value); } public double getValue() { return value; } } It defines a final field called value that is initialized in the constructor, by taking i...

how to extract from dispatch.json.JsObject

What do i need to do to extract the value for friends_count. i noticed that screen_name are already define in the Status object and case class. Do still require to extends Js or JsObject different object TweetDetails extends Js { val friends_count = 'friends_count ? num } and then pattern match it against each json object in the list...

How to force interpreter show complete stack trace?

Is there any way to force Scala interpreter (started through SBT) to print complete stack trace. By default, less than 10 lines are displayed: scala> new CacheMonitoringClient javax.management.InstanceNotFoundException: com.bea:Name=DomainRuntimeService,Type=weblogic.management.beanservers.domainrun time.DomainRuntimeServiceMBean ...

Some languages and uses for monads

Hi guys, According to you, which language do you think would be the best for implementing monads (Python/Ruby/LISP)?,also can anyone tell me some possible uses of monads (please give examples),like exceptions? Thanks in advance ...

Annotating constructor parameters in Scala

Annotating constructor parameters seems to do nothing when compiled to bytecode. I get no compiler warnings either. The following works. getAnnotations for the name field returns javax.annotation.Nullable. class Person { @Nullable var name: String = _; } The following doesn't, neither with val or var. class Person(@Nullable var ...

how do I get sbt to use a local maven proxy repository (Nexus)?

Hello, I've got an sbt (Scala) project that currently pulls artifacts from the web. We'd like to move towards a corporate-standardized Nexus repository that would cache artifacts. From the Nexus documentation, I understand how to do that for Maven projects. But sbt obviously uses a different approach. (I understand Ivy is involved someho...

How to combine Regexp and keywords in Scala parser combinators

I've seen two approaches to building parsers in Scala. The first is to extends from RegexParsers and define your won lexical patterns. The issue I see with this is that I don't really understand how it deals with keyword ambiguities. For example, if my keyword match the same pattern as idents, then it processes the keywords as idents....

Scala or Python to Build a Comet server to support a PHP application?

Hi, I have a currently running PHP application that I want to add real-time feed (Google search latest result feeds), I have an implementation in PHP that does the following: An AJAX request to the server. The PHP responds. After 15000ms (15 seconds) using setTimeout(), we repeat the steps. I knew this have very much overhead on the...

Purpose of "return" statement in Scala?

Is there any real reason of providing the return statement in Scala? (aside from being more "Java-friendly") ...

Is constructor use allowed with case classes?

I have a case class (let's name it Stuff) that I want to be able to create anonymous subclasses of at run time by extending a trait (call it Marker). Here's a snippet of a REPL session that illustrates what I'm trying to do: scala> trait Marker defined trait Marker scala> case class Stuff(i: Int) defined class Stuff scala> val a = Stu...

In Scala, plural object name for a container of public static methods?

I've written a Scala trait, named Cache[A,B], to provide a caching API. The Cache has the following methods, asyncGet(), asyncPut(), asyncPutIfAbsent(), asyncRemove(). I'm going to have a few static methods, such as getOrElseUpdate(key: A)(op: => B). I don't want methods like this as abstract defs in the Cache trait because I don't wa...