scala-2.8

How to implement collection with covariance when delegating to another collection for storage?

I'm trying to implement a type of SortedMap with extended semantics. I'm trying to delegate to SortedMap as the storage but can't get around the variance constraints: class IntervalMap[A, +B](implicit val ordering: Ordering[A]) //extends ... { var underlying = SortedMap.empty[A, List[B]] } Here is the error I get. I understand w...

Expand a Set[Set[String]] into Cartesian Product in Scala

I have the following set of sets. I don't know ahead of time how long it will be. val sets = Set(Set("a","b","c"), Set("1","2"), Set("S","T")) I would like to expand it into a cartesian product: Set("a&1&S", "a&1&T", "a&2&S", ..., "c&2&T") How would you do that? ...

Tutorial on swing in Scala?

Is there a good tutorial showing how to use scala.swing._ ? ...

Using scala.util.control.Exception

Does anybody have good examples of using scala.util.control.Exception? I am struggling to figure it out from the types. ...

idiomatic property changed notification in scala?

I'm trying to find a cleaner alternative (that is idiomatic to Scala) to the kind of thing you see with data-binding in WPF/silverlight data-binding - that is, implementing INotifyPropertyChanged. First, some background: In .Net WPF or silverlight applications, you have the concept of two-way data-binding (that is, binding the value of ...

Packrat parsing HTTP

Hello could somebody give me a start on how to parse the HTTP-protocol with scala 2.8 packrat-parsing? I need to parse attached examplary HTTP Response into ResponseStatusCode:Int Headers:List[(String,String)] Body: String, Array[Byte], CharBuffer or whatever Short examplary usage of a Packrat-Parser very much appreciated. Thanks! ...

How to convert a Seq[A] to a Map[Int, A] using a value of A as the key in the map?

I have a Seq containing objects of a class that looks like this: class A (val key: Int, ...) Now I want to convert this Seq to a Map, using the key value of each object as the key, and the object itself as the value. So: val seq: Seq[A] = ... val map: Map[Int, A] = ... // How to convert seq to map? How can I does this efficiently a...

Why does Iterator have a contains method but Iterable does not, in Scala 2.8?

I would like to call 'contains' on my Iterables :-) ...

Scala 2.8 Actor design document? Akka design document?

Is there a design document for Scala 2.8 Actors, like it is for 2.7? Scala Actors: Unifying Thread-based and Event-based Programming Is there one for Akka? The "Scala Improvement Documents Library" doesn't mention Actors. ...

Use example of Scala ObservableSet Trait

Could anyone help me telling me how to use scala's ObservableSet trait? Thank you very much in advance ...

Collection type generated by for with yield

When I evaluate a for in Scala, I get an immutable IndexedSeq (a collection with array-like performance characteristics, such as efficient random access): scala> val s = for (i <- 0 to 9) yield math.random + i s: scala.collection.immutable.IndexedSeq[Double] = Vector(0.6127056766832756, 1.7137598183155291, ... Does a for with a yield ...

Writing functions of tuples conveniently in Scala

Quite a few functions on Map take a function on a key-value tuple as the argument. E.g. def foreach(f: ((A, B)) ⇒ Unit): Unit. So I looked for a short way to write an argument to foreach: > val map = Map(1 -> 2, 3 -> 4) map: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4) > map.foreach((k, v) => println(k)) error: wrong...

Recursive stream throws StackOverflowError

I am defining a stream in terms of itself (a recursive definition). When trying to access the second element of the stream, StackOverflowError is thrown. The code from scala console: scala> val s1 = Stream.iterate(1)(identity _) s1: scala.collection.immutable.Stream[Int] = Stream(1, ?) scala> lazy val s2 : Stream[Int]= Stream.cons(1, (...

How to use @PersistentCapable annotation in Scala 2.8

Hi, I'm switching from Scala 2.7.7 to Scala 2.8.0RC3 and now a few of my classes don't compile anymore. The problem is in the @PersistentCapable annotation: import javax.jdo.annotations._ import java.util.Date @PersistenceCapable{identityType=IdentityType.APPLICATION} class Counter(dt: Date, cName: String, vl: int) { <.. snip ..> } ...

scala: Adding attributes (odd and even rows) to xml table

In a Lift application, I’d like to add a special tag which takes the <tbody> part of the next table and adds odd and even classes (for example) to each <tr> tag. Alternating, of course. While I have found a way to add another attribute to all <tr> tags, there are still a few problems left (see code below). First, it doesn’t work. cycle....

Java->Scala Remove Iterator<T>-Element from a JavaConversions-wrapped Iterable

I have to translate the following code from Java to Scala: EDIT: added if-statements in the source (forgot them in first version) for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) { if (someCondition) { ExceptionQueuedEvent event = i.next(); try { //do something }...

What is a "context bound" in Scala?

One of the new features of Scala 2.8 are context bounds. What is a context bound and where is it useful? Of course I searched first (and found for example this) but I couldn't find any really clear and detailed information. ...

IntelliJ IDEA 9 and Scala 2.8

I have a problem with IntelliJ IDEA 9.0's debugger when I run scala code (scala 2.8). The problem is that I can't see which case is selected in the match sentence when I make traces step by step. ...

Minimal framework in Scala for collections with inheriting return type

Suppose one wants to build a novel generic class, Novel[A]. This class will contain lots of useful methods--perhaps it is a type of collection--and therefore you want to subclass it. But you want the methods to return the type of the subclass, not the original type. In Scala 2.8, what is the minimal amount of work one has to do so tha...

Get name of class-attribute or class-function as String

Say i have the following class: class Person { @BeanProperty var firstName: String = _ } Is it possible to get the String representation of "firstName" in a type-safe way, by reflection or something? Or the String representation of the generated "getFirstName"-Function? It would be nice if it would somehow look like: val p = new...