Questions tagged [scala-2.9]

Version 2.9 of the Scala language for the JVM.

scala-2.9
Filter by
Sorted by
Tagged with
179 votes
17 answers
155k views

Scala: write string to file in one statement

For reading files in Scala, there is Source.fromFile("file.txt").mkString Is there an equivalent and concise way to write a string to file? Most languages support something like that. My favorite ...
smartnut007's user avatar
  • 6,394
52 votes
1 answer
24k views

What is the === (triple-equals) operator in Scala Koans?

I started working my way through the Scala Koans, which is organized around a suite of unit tests with blanks that one needs to fill in. (This idea was modeled after a similar Ruby Koans project.) ...
pohl's user avatar
  • 3,167
37 votes
4 answers
6k views

Is there a way to declare an implicit val inside a for comprehension?

I have some code with nested calls to flatMap like so: foo.flatMap(implicit f => bar(123).flatMap(b => /* and so on... implicit f is still in scope here.*/ )) Normally, one would write that ...
Kim Stebel's user avatar
29 votes
4 answers
12k views

SBT including the version number in a program

I want a program I'm building to be able to report its own version at runtime (e.g. scala myprog.jar --version). Traditionally in a maven project, I'd use resource filtering (pom.xml -> file....
Chris Eberle's user avatar
  • 48.3k
21 votes
9 answers
40k views

coin change algorithm in scala using recursion

I am trying to program the coin change problem in Scala using recursion. The code that i have written is as follows. def countChange(money: Int, coins: List[Int]): Int = { def ways(change: List[Int]...
Muavia's user avatar
  • 408
20 votes
7 answers
5k views

How can I fix the missing implicit value for parameter ta: TildeArrow in a test spec

I'm working on a simple test spec using spray and I can't get it to compile correctly, don't know if I'm doing anything wrong. My version of scala is 2.9.3 and spray 1.0.1 (Updating either of them is ...
marcelaconejo's user avatar
19 votes
2 answers
2k views

How do I replace the fork join pool for a Scala 2.9 parallel collection?

I've been looking at the new Scala 2.9 parallel collections and am hoping to abandon a whole lot of my crufty amateur versions of similar things. In particular, I'd like to replace the fork join pool ...
Scott Morrison's user avatar
18 votes
2 answers
7k views

Add tools.jar in the classpath of sbt project

The ':javap' command in the scala 2.9.1 console need the tools.jar (from JDK6) in the 'classpath'. From cmd-line it could be done with '-cp' argument or CLASSPATH environment variable. How to do the ...
andy legkiy's user avatar
18 votes
4 answers
3k views

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?
Kevin Wright's user avatar
  • 49.6k
15 votes
3 answers
2k views

Why do case classes extend only Product and not Product1, Product2, ..., ProductN?

after I learned that case classes extend Product, I wondered why they do not extend ProductN. E.g., given a code like: case class Foo(a: Int) I'd expect Foo(1).asInstanceOf[Product1[Int]] to work, ...
Blaisorblade's user avatar
  • 6,468
15 votes
1 answer
3k views

How can I best troubleshoot "Potentially incompatible versions of dependencies" in sbt

My project gives the following warning: [warn] Potentially incompatible versions of dependencies of {file:/some/path/}default-5bae4a: [warn] org.scala-lang: 2.9.2, 2.9.1 I've got the following ...
iwein's user avatar
  • 26k
14 votes
3 answers
1k views

Scala Parallel Collections- How to return early?

I have a list of possible input Values val inputValues = List(1,2,3,4,5) I have a really long to compute function that gives me a result def reallyLongFunction( input: Int ) : Option[String] = { ......
bwawok's user avatar
  • 15k
11 votes
2 answers
2k views

Parallel collections in Scala 2.9 and Actors

Ok, this might be a rather silly question, but what is the benefit of using parallel collections within an actor framework? That is, if I'm only dealing with one message at a time from an actor's ...
Bruce Ferguson's user avatar
10 votes
2 answers
2k views

How do you make a list with 100 1s in Scala 2.9

In earlier versions of Scala you can use List.make(100, 1), but that is now deprecated. What is the new proper way to do it?
placeybordeaux's user avatar
10 votes
1 answer
1k views

What is Scala REPL's tab completion telling me here?

While working my way through Cay S. Horstmann's "Scala for the Impatient", I noticed something interesting revealed by the first exercise in the first chapter. In the Scala REPL, type 3. followed by ...
pohl's user avatar
  • 3,167
9 votes
2 answers
17k views

Getting started with Scala, Scalatest, and Maven

I created a new scala project with the following: mvn org.apache.maven.plugins:maven-archetype-plugin:2.2:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-...
MrDrews's user avatar
  • 2,137
9 votes
1 answer
523 views

Strange behavior of Set4 in scala 2.9.1?

Making a migration from 2.8.1 to 2.9.1 found interesting thing. Tried to write this in console: >>import collection.immutable.Set.Set4 >>new Set4[Int](1,2,3,4) It gives: java.lang.Error:...
Rinat Tainov's user avatar
  • 1,489
8 votes
1 answer
5k views

How can I sort List[Int] objects?

What I want to do is sort List objects in Scala, not sort the elements in the list. For example If I have two lists of Ints: val l1 = List(1, 2, 3, 7) val l2 = List(1, 2, 3, 4, 10) I want to be able ...
Mike Lavender's user avatar
8 votes
1 answer
3k views

Reference a constructor argument from a trait

In Scala, is it possible for a trait to reference a named constructor argument of the class it is mixed into? The code below doesn't compile because ModuleDao's constructor argument is not a val as ...
Nick's user avatar
  • 11.5k
8 votes
3 answers
534 views

Case classes and Proxy behaviour in Scala 2.9

On migrating our code to Scala 2.9 we've found large swathes of it that didn't work and failed silently. We tracked it down to case classes that extend Proxy not being equal. In our code we don't ...
David's user avatar
  • 1,914
7 votes
3 answers
4k views

converting Akka's Future[A] to Future[Either[Exception,A]]

Is there a method in Akka (or in the standard library in Scala 2.10) to convert a Future[A] which might fail into a Future[Either[Exception,A]]? I know that you can write f.map(Right(_)).recover { ...
Kim Stebel's user avatar
7 votes
1 answer
405 views

Why doesn't scala's parallel sequences have a contains method?

Why does List.range(0,100).contains(2) Work, while List.range(0,100).par.contains(2) Does not? This is planned for the future?
placeybordeaux's user avatar
7 votes
2 answers
17k views

Constructor cannot be instantiated to expected type; p @ Person

I am using scala version : Scala code runner version 2.9.2-unknown-unknown -- Copyright 2002-2011, LAMP/EPFL I was trying the deep case matching construct from here: http://ofps.oreilly.com/titles/...
tuxdna's user avatar
  • 8,377
7 votes
2 answers
4k views

What is the fastest way to subtract two arrays in scala

I have two arrays (that i have pulled out of a matrix (Array[Array[Int]]) and I need to subtract one from the other. At the moment I am using this method however, when I profile it, it is the ...
Mike Lavender's user avatar
7 votes
1 answer
1k views

Why is this not faster using parallel collections?

I just wanted to test the parallel collections a bit and I used the following line of code (in REPL): (1 to 100000).par.filter(BigInt(_).isProbablePrime(100)) against: (1 to 100000).filter(BigInt(_)...
Plankalkül's user avatar
7 votes
1 answer
2k views

How should one start on creating a sbt plugin?

I want to create a sbt plugin for Scala project. Please any one suggest me how we start? I referred Plugins documentation but unable to understand steps.
Anuj Pratap Singh's user avatar
7 votes
1 answer
729 views

What are main changes from scala 2.8.1 to scala 2.9.1?

I am working on project implemented in scala 2.8.1, want to migrate to scala 2.9.1 and use akka-actors libraries instead of standard, but didn't find good summary of main changes, here what I found: ...
Rinat Tainov's user avatar
  • 1,489
7 votes
1 answer
3k views

How to convert scala.collection.Set to java.util.Set with serializable within an RDD

I have a scala.collection.Set scalaSet : Set[Long]. How will I be able to convert it into a java.util.Set with serializable. I tried the following code, but got java.io.notserializableexception: ...
user3658637's user avatar
7 votes
3 answers
1k views

Modifying a large file in Scala

I am trying to modify a large PostScript file in Scala (some are as large as 1GB in size). The file is a group of batches, with each batch containing a code that represents the batch number, number of ...
Andrew Conner's user avatar
7 votes
1 answer
1k views

How does one implement a Hadoop Mapper in Scala 2.9.0?

When I migrated to Scala 2.9.0 from 2.8.1, all of the code was functional except for the Hadoop mappers. Because I had some wrapper objects in the way, I distilled down to the following example: ...
Chris B's user avatar
  • 71
7 votes
1 answer
810 views

In which case can Scala 2.10.0 compiler be faster or slower than 2.9.2?

I did a benchmark for compilation time on Scala 2.10.0 and 2.9.2, and have found that 2.10.0 took longer compilation time than 2.9.2. In which case does it happen? Or can Scala 2.10.0 compiler be ...
Kenji Yoshida's user avatar
6 votes
2 answers
4k views

Scala List Comprehensions

I'm trying to generate a list in scala according to the formula: for n > 1 f(n) = 4*n^2 - 6*n + 6 and for n == 1 f(n) = 1 currently I have: def lGen(end: Int): List[Int] = { for { n <- ...
LeeG's user avatar
  • 275
6 votes
3 answers
615 views

Dynamic Proxy using Scalas new Dynamic Type

Is it possible to create an AOP like interceptor using Scalas new Dynamic Type feature? For example: Would it be possible to create a generic stopwatch interceptor that could be mixed in with ...
gruenewa's user avatar
  • 1,686
6 votes
1 answer
610 views

Array[Nothing with java.lang.Object] required in Scala 2.9.1

I have a weird compilation error. The offending lines are: val comboBoxLanguage = new javax.swing.JComboBox //... comboBoxLanguage.setModel(new javax.swing.DefaultComboBoxModel( Array[Object]("...
Luigi Plinge's user avatar
  • 50.9k
6 votes
2 answers
1k views

Step by step guide to get Scala to run on .net?

I have never used .Net framework and need to demonstrate to someone that Scala indeed works on .Net. I need to get a "quick and dirty" .Net setup with Scala working on some existing JVM Scala code. I ...
Jus12's user avatar
  • 18k
6 votes
3 answers
209 views

Generic collect by type in scala

In Scala 2.9.1 With def collectFirstOfT[T](la: List[_])(implicit m:Manifest[T]) : Option[T] = { la.collect{case x if m.erasure.isAssignableFrom(x.getClass) => x}. headOption.asInstanceOf[...
jwinandy's user avatar
  • 1,749
6 votes
3 answers
491 views

Using ListView from Scala 2.9.2 with Java 7 gives compile error

I'm working on a project that use scala 2.9.2 and java 7. What I'm trying to do is create a GUI using the scala ListView. Here's a small code snippet: private val listView = new ListView[Document](...
ulejon's user avatar
  • 641
6 votes
1 answer
695 views

Scala 2.9 Bridge-Method

I'm using Scala 2.9.1 I've defined a Logging trait as such: trait Logging { def debug(msg: String, throwables: Throwable*) = .... .... } And I have a JMSPublisher class which mixes-in the ...
shj's user avatar
  • 1,628
6 votes
1 answer
792 views

Is this a bug in scala 2.9.0.1 actor library

The following code works fine in Scala 2.8 but not in 2.9.0.1 (copy and paste in REPL). This will throw an exception in 2.9.0.1. import scala.actors.Actor import scala.actors.TIMEOUT object A2 ...
Jus12's user avatar
  • 18k
5 votes
3 answers
8k views

How can I use Scala's MurmurHash implementation: scala.util.MurmurHash3?

I'm writing a BloomFilter and wanted to use Scala's default MurmurHash3 implementation: scala.util.MurmurHash3. My compile is failing however with the following compile error: [error] /mnt/hgfs/dr/...
dr.'s user avatar
  • 247
5 votes
1 answer
617 views

How do I use nightly builds of Scala 2.9 with maven?

Recently I wanted to try some of the new features in Scala 2.9 in a small project. I would like to use maven for building it. How can I tell Maven to use the latest nightly build of Scala 2.9? If ...
Kim Stebel's user avatar
5 votes
1 answer
323 views

How can I override a method with a dependent return type?

I'm having trouble in Scala 2.9.2 implementing a method which declares a dependent return type. The following code object DependentTypesQuestion { def ??? = throw new UnsupportedOperationException ...
Scott Morrison's user avatar
5 votes
1 answer
410 views

Why does Scala define a "+=" operator for Short and Byte types?

Given the following scala code: var short: Short = 0 short += 1 // error: type mismatch short += short // error: type mismatch short += 1.toByte // error: type mismatch I don't questioning ...
Richard Sitze's user avatar
5 votes
0 answers
1k views

What IDEs support SBT and Scala version 2.9.0 [duplicate]

Possible Duplicate: Which IDE for Scala 2.8? I would like to know which IDEs specifically support Scala 2.9 and the sbt project ?
ouertani's user avatar
  • 347
4 votes
1 answer
4k views

counting down in scala for loop [duplicate]

Possible Duplicate: Decreasing for loop in Scala? While working through [Scala For The Impatient][1], I came upon the following exercise: Write a Scala equivalent for the Java loop for (int i ...
pohl's user avatar
  • 3,167
4 votes
1 answer
3k views

How to import class using fully qualified name?

create file test1.scala with following code: package test import java.io.FileInputStream object Foo create another file test2.scala with following code: package test.java object Bar Now compile ...
Jus12's user avatar
  • 18k
4 votes
3 answers
2k views

Scala: Generic class with multiple constructors

I'm trying to create a generic class like this: class A[T](v: Option[T]) { def this(v: T) = this(Some(v)) def this() = this(None) def getV = v } Then I do some testing: scala> new A getV ...
Vilius Normantas's user avatar
4 votes
3 answers
2k views

Scala 2.10 vs. 2.9 incompatibilities [closed]

What are the Scala 2.10 vs. 2.9 incompatibilities and how to deal with them? Especially core libraries, but any issues with popular libraries might be interesting. Links to official documents are ...
Jakozaur's user avatar
  • 1,977
4 votes
1 answer
231 views

Methods in trait become volatile methods when mixed in concrete classes in 2.9.0-1 but not 2.8.1

I noticed this breaking (for me using it with OGNL) change in 2.9.0-1: I find that, in 2.9, methods declared in a trait become volatile when mixed in a class: Example in 2.9.0-1 import java.lang....
andreak's user avatar
  • 912
4 votes
1 answer
163 views

Why does 2.10 insist on specifying type parameter bounds (worked fine in 2.9)?

I have the following case class: case class Alert[T <: Transport](destination: Destination[T], message: Message[T]) In Scala 2.9.2, the following method signature has compiled fine: def send(...
pr1001's user avatar
  • 21.9k