When is @uncheckedVariance needed in Scala, and why is it used in GenericTraversableTemplate?

The problem is that GenericTraversableTemplate is used twice: once for mutable collections (where its type parameter should be invariant), and once for immutable collections (where covariance is invariably king). GenericTraversableTemplate’s typechecks assuming either covariance or invariance for the A type parameter. However, when we inherit it in a mutable trait, we have to pick invariance. … Read more

Which IDE for Scala 2.8? [closed]

I’ve been pretty successful with IDEA 9. I’ve briefly tried both Netbeans and Eclipse and wasn’t able to get what I wanted. Eclipse’s code-complete didn’t behave as well as I’d have liked, and I couldn’t find a way to make Netbeans handle Scala scripts; It’d just complain that the file wasn’t a class. To be … Read more

How can I convert immutable.Map to mutable.Map in Scala?

The cleanest way would be to use the mutable.Map varargs factory. Unlike the ++ approach, this uses the CanBuildFrom mechanism, and so has the potential to be more efficient if library code was written to take advantage of this: val m = collection.immutable.Map(1->”one”,2->”Two”) val n = collection.mutable.Map(m.toSeq: _*) This works because a Map can also … Read more

Scala 2.8 CanBuildFrom

Note that the second argument to map is an implicit argument. There must be an implicit in scope with the appropriate types, or, otherwise, you must pass such an argument. In your example, That must be Set[String], B must be Int and Repr must be List[String]. Therefore, for that to compile you need the following … Read more

Implementing yield (yield return) using Scala continuations

Before we introduce continuations we need to build some infrastructure. Below is a trampoline that operates on Iteration objects. An iteration is a computation that can either Yield a new value or it can be Done. sealed trait Iteration[+R] case class Yield[+R](result: R, next: () => Iteration[R]) extends Iteration[R] case object Done extends Iteration[Nothing] def … Read more