scala

Removing nodes from XML

I want to produce an XML document from another, filtering subnodes that match a specified criterion. How should I do that? ...

scala and traits on object instances

hi, if i have a trait: trait MyTrait { def doSomething = { println("boo") } } I can add it to a class with "extends": class MyClass extends MyTrait { .... } or i can add it to a new object when i construct it: var o = new MyOtherClass with MyTrait o.doSomething but... can i add it to an existing ob...

How to write a zipWith method that returns the same type of collection as those passed to it?

I have reached this far: implicit def collectionExtras[A](xs: Iterable[A]) = new { def zipWith[B, C, That](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: CanBuildFrom[Iterable[A], C, That]) = { val builder = cbf(xs.repr) val (i, j) = (xs.iterator, ys.iterator) while(i.hasNext && j.hasNext) { builder += f(i.next, j.ne...

How to use MySQL JDBC driver in an SBT Scala broject?

When I run my project for the first time during an SBT session, it throws the following exception when trying to access a MySQL database: java.lang.NoClassDefFoundError: scala/Ordered When I run it again (and any time after it, during the same SBT session), it throws a different one: java.sql.SQLException: No suitable driver fo...

Scala specs: nest in-statements

Hi, is it possible to nest following specs test code "ClassX" should { "throw an IllegalArgumentException if n < 0" in { ClassX(-1) must throwA[IllegalArgumentException] } "throw an IllegalArgumentException if n > 50" in { ClassX(51) must throwA[IllegalArgumentException] } "throw an IllegalArgumentException if n == 35...

How to initialize a Scala immutable hashmap with values?

What's the syntax to set immutable hashmap contents on initialization? For example, if I was willing to hardcode an array, I'd write: val a = Array (0, 1, 2, 3) What's the analogue for immutable hashmaps (say I want it to contain 0->1 and 2->3 pairs) (in Scala 2.8)? ...

Can I have Scala 2.8 reference documentation offline?

Is there a way to have full standard Scala library documentation off-line? ...

Can't I define defaults if I define multiple overloaded constructors in Scala?

I've defined multiple constructors, with some default argument values in all of them. Looks correct (I can't see any ambiguity), but Scala (2.8) compiler complains: multiple overloaded alternatives of constructor define default arguments Does it mean that I can't define default values for overloaded constructors at all? Let me ill...

Problem with specifying enumeration value types.

I have a problem with specifying types for enumeration values (instances of scala.Enumeration) in functions. This originally arises from my need to serialize enumeration objects in database, but I've extracted the problematic code in the following example: object EnumerationTypes { class EnumerationProcessor[E <: Enumeration](enum: E...

Cleaner way to update nested structures

Say I have got following two case classes: case class Address(street: String, city: String, state: String, zipCode: Int) case class Person(firstName: String, lastName: String, address: Address) and the following instance of Person class: val raj = Person("Raj", "Shekhar", Address("M Gandhi Marg", ...

How do I use the trait scala.Proxy

I just found it in the API (http://www.scala-lang.org/api/current/scala/Proxy.html) and would like to see one or two examples along with an explanation what it is good for. ...

What new features will be added to Scala 2.9?

I know parallel collections will become available. What form will these take, and what else are we likely to see? ...

Dynamic Proxy without explicitely specifying the type in scala

is it possible to have a method that takes an arbitrary instance and returns a java.reflection.Proxy or similar that has the same type as the original argument? I guess it should look something like this: def createProxy[S](model: S)(implicit manifest: Manifest[S]): S = {...} or this def createProxy[S, T<:S](model: S)(implicit manif...

Explicitly defined setter not found in assignment expression

I have a small conundrum when it comes to Scala properties. Various blogs and tutorials tell me that this: class Something { var foo = 1 } ...can be specified as... class Something { private var _field = 1 def foo = _field def foo_(foo: Int) = _field = foo } This makes perfect sense to me, when doing assignment th...

How to get an object's specific type and cast the object to it in Scala?

For example GeneralType is a class or a trait extended by many more specific types, including, to say, SpecificType. A function takes an argument of type GeneralType, and then whant's no know if the actual argument passed is a SpecificType instance and act accordingly (use its special fields/methods) if it is. How to code this in Sca...

How do I embed the Scala 2.8 interpreter in a Java application?

I want to be be able to manipulate objects in memory in my Java app interactively for debugging purposes. I would quite like to do this using Scala's 2.8 interpreter, taking advantages of its features like tab-completion. How do I do this? ...

Is using scala on android worth it? Is there a lot of overhead? Problems?

I was thinking of building an app on android with Scala instead of the regular Java (or the equivalent I guess). Is it worth it? Any problems and unnecessary headaches? ...

How to correctly type-annotate this HList?

sealed abstract trait HList case class :+:[H, T <: HList](head: H, tail: T) extends HList { def :+:[T](v: T) = new :+:(v, this) } case object HNil extends HList { def :+:[T](v: T) = new :+:(v, this) } object HListExpt { def main(args: Array[String]) { val me: String :+: Int :+: Symbol :+: HNil.type = "Rahul" :+: 20 :+: 'Male...

Strange issue with using Java ProcessBuilder on Windows 2008 R2 Standard

Hi all, I've delopped some Scala code to control the lifecycle of MySQL server. The code runs fine on Windows XP, but fails under Windows 2008 R2 standard with the following exception: Exception in thread "main" java.io.IOException: Cannot run program "mysql" (in directory ".\bin"): CreateProcess error=2, The system cannot find the fil...

Reassignment to a val in Scala

Hello, I am doing a training exercise in Scala and getting this val reassignment error. I don't see where I am reassigning a new value to a val class personTest { val alf = Person("Alf", 30, List(EmailAddress("[email protected]"))) val fredrik = Person("Fredrik", 33, List(EmailAddress("[email protected]"), EmailAddress("fvr@...