Questions tagged [scala-2.8]

Version 2.8 of the Scala language for the JVM. Use only if your question is specifically related to features of this version.

Filter by
Sorted by
Tagged with
872 votes
18 answers
116k views

Is the Scala 2.8 collections library a case of "the longest suicide note in history"? [closed]

I have just started to look at the Scala collections library re-implementation which is coming in the imminent 2.8 release. Those familiar with the library from 2.7 will notice that the library, from ...
232 votes
4 answers
39k views

Scala 2.8 breakOut

In Scala 2.8, there is an object in scala.collection.package.scala: def breakOut[From, T, To](implicit b : CanBuildFrom[Nothing, T, To]) = new CanBuildFrom[From, T, To] { def apply(from: ...
oxbow_lakes's user avatar
213 votes
4 answers
34k views

What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

I can see in the API docs for Predef that they're subclasses of a generic function type (From) => To, but that's all it says. Um, what? Maybe there's documentation somewhere, but search engines don'...
Jeff's user avatar
  • 15.4k
160 votes
19 answers
165k views

How to write to a file in Scala?

For reading, there is the useful abstraction Source. How can I write lines to a text file?
yura's user avatar
  • 14.6k
118 votes
4 answers
35k views

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 ...
Jesper's user avatar
  • 205k
113 votes
2 answers
82k views

Overload constructor for Scala's Case Classes?

In Scala 2.8 is there a way to overload constructors of a case class? If yes, please put a snippet to explain, if not, please explain why?
Felix's user avatar
  • 8,435
109 votes
6 answers
65k views

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

How can I convert immutable.Map to mutable.Map in Scala so I can update the values in Map?
Łukasz Lew's user avatar
  • 49.4k
97 votes
4 answers
39k views

Package objects

What are package objects, not so much the concept but their usage? I've tried to get an example working and the only form I got to work was as follows: package object investigations { val ...
Don Mackenzie's user avatar
86 votes
7 answers
25k views

What are Scala continuations and why use them?

I just finished Programming in Scala, and I've been looking into the changes between Scala 2.7 and 2.8. The one that seems to be the most important is the continuations plugin, but I don't understand ...
Dave's user avatar
  • 7,639
73 votes
1 answer
20k views

Scala 2.8 collections design tutorial

Following on from my breathless confusion, what are some good resources which explain how the new Scala 2.8 collections library has been structured. I'm interested to find some information on how the ...
oxbow_lakes's user avatar
65 votes
1 answer
17k views

Does the @inline annotation in Scala really help performance?

Or does it just clutter up the code for something the JIT would take care of automatically anyway?
Alex R's user avatar
  • 11.6k
56 votes
6 answers
50k views

How to choose a random element from an array in Scala?

For example, there is a Scala array val A = Array("please", "help", "me"). How to choose a random element from this array?
sam's user avatar
  • 2,103
52 votes
4 answers
45k views

What's the right way to use scala.io.Source?

In many examples, it is described that you can use scala.io.Source to read a whole file like this: val str = scala.io.Source.fromFile("test.txt").mkString() But closing the underlying stream is not ...
woods's user avatar
  • 827
52 votes
1 answer
15k views

How do I exclude/rename some classes from import in Scala?

Language FAQ says import scala.collection.mutable.{_, Map => _, Set => _} should import all classes from package scala.collection.mutable, except Map and Set. But it gives me this error: ...
Alexey Romanov's user avatar
51 votes
6 answers
31k views

Scala Map implementation keeping entries in insertion order?

In Java, I use LinkedHashMap for this purpose. The documentation of Java's LinkedHashMap is very clear that it has "predictable iteration order" and I need the same in Scala. Scala has ListMap and ...
ebruchez's user avatar
  • 7,817
50 votes
4 answers
57k views

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 ...
Jesper's user avatar
  • 205k
50 votes
1 answer
5k views

Function syntax puzzler in scalaz

Following watching Nick Partidge's presentation on deriving scalaz, I got to looking at this example, which is just awesome: import scalaz._ import Scalaz._ def even(x: Int) : Validation[NonEmptyList[...
oxbow_lakes's user avatar
49 votes
9 answers
34k views

How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far. I've been able to edit programs (within syntax ...
Alex R's user avatar
  • 11.6k
40 votes
4 answers
34k views

Scala foldLeft on Maps

How do you use Map.foldLeft? According to the docs it looks like foldLeft [B] (z: B)(op: (B, (A, B)) ⇒ B) : B But I'm having difficulty: Map("first"->1,"second"->2).foldLeft(0)((a,(k,v)) =&...
Pengin's user avatar
  • 4,742
40 votes
17 answers
17k views

Which IDE for Scala 2.8? [closed]

This is the same question for older version of Scala, but they say that Eclipse plugin has been improved vastly. Is it the best IDE now? How do different Scala IDE compare today?
Łukasz Lew's user avatar
  • 49.4k
40 votes
4 answers
3k views

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

@uncheckedVariance can be used to bridge the gap between Scala's declaration site variance annotations and Java's invariant generics. scala> import java.util.Comparator import java.util....
retronym's user avatar
  • 54.9k
36 votes
1 answer
21k views

What's the new way to iterate over a Java Map in Scala 2.8.0?

How does scala.collection.JavaConversions supercede the answers given in Stack Overflow question Iterating over Java collections in Scala (it doesn't work because the "jcl" package is gone) and in ...
Alex R's user avatar
  • 11.6k
31 votes
2 answers
6k views

Using scala.util.control.Exception

Does anybody have good examples of using scala.util.control.Exception version 2.12.0 (version 2.8.0), ? I am struggling to figure it out from the types.
Alexey Romanov's user avatar
29 votes
4 answers
26k views

In Scala, is there a way to take convert two lists into a Map?

I have a two lists, a List[A] and a List[B]. What I want is a Map[A,B] but I want the semantics of zip. So started out like so: var tuplesOfAB = listOfA zip listOfB Now I'm not sure how to construct ...
Andy Hull's user avatar
  • 1,873
28 votes
5 answers
17k views

Convert Scala Set into Java (java.util.Set)?

I have a Set in Scala (I can choose any implementation as I am creating the Set. The Java library I am using is expecting a java.util.Set[String]. Is the following the correct way to do this in Scala ...
or9ob's user avatar
  • 2,352
28 votes
2 answers
7k views

Scala 2.8 CanBuildFrom

Following on from another question I asked, Scala 2.8 breakout, I wanted to understand a bit more about the Scala method TraversableLike[A].map whose signature is as follows: def map[B, That](f: A =&...
oxbow_lakes's user avatar
27 votes
7 answers
2k views

Questions about Scala from a Rubyist

I have recently been looking around to learn a new language during my spare time and Scala seems to be very attractive. I have a few questions regarding it: Will not knowing Java impose a challange ...
jinx's user avatar
  • 271
27 votes
2 answers
7k views

Implementing yield (yield return) using Scala continuations

How might one implement C# yield return using Scala continuations? I'd like to be able to write Scala Iterators in the same style. A stab is in the comments on this Scala news post, but it doesn't ...
xyzzyrz's user avatar
  • 16.2k
27 votes
3 answers
2k views

What is the concept of "weak conformance" in Scala?

I just recently encountered the term "Weak Conformance" (in Stack Overflow user retronym's answer to How to set up implicit conversion to allow arithmetic between numeric types?). What is it?
Randall Schulz's user avatar
26 votes
6 answers
7k views

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 ...
Alexey Romanov's user avatar
25 votes
3 answers
4k views

What is the difference between a view and a stream?

In the Scala 2.8 collections framework, what is the difference between view and toStream?
Craig P. Motlin's user avatar
23 votes
3 answers
3k views

What are nested/unnested packages in Scala 2.8?

In Scala 2.7, I could write: package com.acme.bar class Bar . package com.acme.foo class Foo { new bar.Bar } This doesn't compile in Scala 2.8 -- however this does: package com.acme package ...
retronym's user avatar
  • 54.9k
23 votes
5 answers
17k views

Are there a good examples of using 'scala.swing'? [closed]

I don't know Java or Swing, but I'm quite familiar with Scala, and I have no problems using it for my purposes. But when I try to implement a GUI, I get a lot of problems/bugs that documentation can't ...
Łukasz Lew's user avatar
  • 49.4k
23 votes
2 answers
1k views

Don't understand the typing of Scala's delimited continuations (A @cpsParam[B,C])

I'm struggling to understand what precisely does it mean when a value has type A @cpsParam[B,C] and what types of this form should I assign to my values when using the delimited continuations facility....
22 votes
4 answers
18k views

How to find a matching element in a list and map it in as an Scala API method?

Is there a method to do the following without doing both methods: find and map? val l = 0 to 3 l.find(_ * 33 % 2 == 0).map(_ * 33) // returns Some(66)
agilefall's user avatar
  • 3,896
22 votes
3 answers
2k views

What compromises Scala made to run on JVM?

Scala is a wonderful language, but I wonder how could be improved if it had it's own runtime? I.e. what design choices were made because of JVM choice?
Łukasz Lew's user avatar
  • 49.4k
22 votes
2 answers
13k views

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 ...
Jesper's user avatar
  • 205k
21 votes
5 answers
2k views

What are the good Scala IDEs at the start of 2010?

I know this is an exact duplicate, but a year has gone by and Scala seems to be a fast moving thing, so I figure it might be acceptable to ask again: What is the best IDE for Scala development right ...
Jens Schauder's user avatar
21 votes
4 answers
21k views

Scala: is it possible to override default case class constructor?

Just wondering if this is possible. What I would actually like to do is check and possibly modify one of the arguments before it is stored as a val. Alternatively, I could use an overload and make ...
adam77's user avatar
  • 2,867
20 votes
3 answers
4k views

Scala collection type for filter

Assume you have a List(1,"1") it is typed List[Any], which is of course correct and expected. Now if I map the list like this scala> List(1, "1") map { | case x: Int => x | case y:...
Joa Ebert's user avatar
  • 6,655
20 votes
3 answers
3k views

In Scala 2.8 collections, why was the Traversable type added above Iterable?

I know that to be Traversable, you need only have a foreach method. Iterable requires an iterator method. Both the Scala 2.8 collections SID and the "Fighting Bitrot with Types" paper are basically ...
Seth Tisue's user avatar
  • 30.3k
19 votes
2 answers
16k views

Mixing Scala and Java files in an Eclipse project

I'm probably doing something stupid, but I can't spot it. I've installed Eclipse Helios (Helios because I couldn't get Glassfish support to work correctly using Gallileo) and the nightly build of the ...
The Archetypal Paul's user avatar
18 votes
3 answers
10k views

Why does this explicit call of a Scala method allow it to be implicitly resolved?

Why does this code fail to compile, but compiles successfully when I uncomment the indicated line? (I'm using Scala 2.8 nightly). It seems that explicitly calling string2Wrapper allows it to be used ...
Matt R's user avatar
  • 10.2k
18 votes
3 answers
3k views

Is it possible for an optional argument value to depend on another argument in Scala

Does anyone know if something like this is possible in Scala: case class Thing(property:String) def f(thing:Thing, prop:String = thing.property) = println(prop) The above code doesn't compile; ...
Kristian Domagala's user avatar
18 votes
3 answers
5k views

Proxies / delegates in Scala

I've seen several Scala questions recently (e.g. here, here, and here) that called for the use of proxies, and it's come up more than once in my own work. The Scala library has a number of proxy ...
Aaron Novstrup's user avatar
17 votes
2 answers
17k views

Scala Array constructor?

scala> val a = Array [Double] (10) a: Array[Double] = Array(10.0) scala> val a = new Array [Double] (10) a: Array[Double] = Array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) Why these ...
Łukasz Lew's user avatar
  • 49.4k
17 votes
1 answer
9k views

What is the most straightforward way to parse JSON in Scala?

I'm working on a simple web application with Scala. The plan is to obtain JSON data from an external API, and insert it into a template (unfortunately, obtaining the data in XML is not an option). I'...
JAL's user avatar
  • 21.5k
17 votes
2 answers
8k views

scala Remove (in place) all elements of a ListBuffer that meet a condition

I have a ListBuffer. I want to remove all elements that meet a certain condition. I could iterate over it and remove each element. But what doe Scala say about mutating a list that you are iterating ...
The Archetypal Paul's user avatar
16 votes
2 answers
5k views

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

I would like to call 'contains' on my Iterables :-)
adam77's user avatar
  • 2,867
16 votes
2 answers
2k views

Scalaz: request for use case for Cokleisli composition

This question isn't meant as flame-bait! As it might be apparent, I've been looking at Scalaz recently. I'm trying to understand why I need some of the functionality that the library provides. Here's ...
oxbow_lakes's user avatar

1
2 3 4 5
8