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 a usage perspective, has changed little. For…
It seems that Vector was late to the Scala collections party, and all the influential blog posts had already left.
In Java ArrayList is the default collection - I might use LinkedList but only when I've thought through an algorithm and care enough…
In scala.collection, there are two very similar objects JavaConversions and JavaConverters.
What is the difference between these two objects?
Why do they both exist?
When do I want to use one vs. the other?
When should I use reduceLeft, reduceRight, foldLeft, foldRight, scanLeft or scanRight?
I want an intuition/overview of their differences - possibly with some simple examples.
If I have a collection c of type T and there is a property p on T (of type P, say), what is the best way to do a map-by-extracting-key?
val c: Collection[T]
val m: Map[P, T]
One way is the following:
m = new HashMap[P, T]
c foreach { t => m add…
In what cases I should use Array(Buffer) and List(Buffer). Only one difference that I know is that arrays are nonvariant and lists are covariant. But what about performance and some other characteristics?
What are the differences among Streams, Views (SeqView), and Iterators in scala? This is my understanding:
They are all lazy lists.
Streams cache the values.
Iterators can only be used once? You can't go back to the beginning and evaluate the value…
I have a folder structure like below:
- main
-- java
-- resources
-- scalaresources
--- commandFiles
and in that folders I have my files that I have to read.
Here is the code:
def readData(runtype: String, snmphost: String, comstring: String,…
Being new to Scala (2.9.1), I have a List[Event] and would like to copy it into a Queue[Event], but the following Syntax yields a Queue[List[Event]] instead:
val eventQueue = Queue(events)
For some reason, the following works:
val eventQueue =…
Learning Scala currently and needed to invert a Map to do some inverted value->key lookups. I was looking for a simple way to do this, but came up with only:
(Map() ++ origMap.map(kvp=>(kvp._2->kvp._1)))
Anybody have a more elegant approach?
I am trying to get a subarray in scala, and I am a little confused on what the proper way of doing it is. What I would like the most would be something like how you can do it in python:
x = [3, 2, 1]
x[0:2]
but I am fairly certain you cannot do…
EDIT: Re-written this question based on original answer
The scala.collection.immutable.Set class is not covariant in its type parameter. Why is this?
import scala.collection.immutable._
def foo(s: Set[CharSequence]): Unit = {
println(s)
}
def…
Related to Stack Overflow question Scala equivalent of new HashSet(Collection) , how do I convert a Java collection (java.util.List say) into a Scala collection List?
I am actually trying to convert a Java API call to Spring's SimpleJdbcTemplate,…