I have a sequence of key-value pairs (String, Int), and I want to group them by key into a sequence of values (i.e. Seq[(String, Int)]) => Map[String, Iterable[Int]])).
Obviously, toMap isn't useful here, and groupBy maintains the values as tuples.…
I'm trying to convert back from a parallel collection to a regular map. According to the api, if I call toMap on any appropriately defined parallel collection, it's supposed to return a standard Map, but it's returning ParMap over a flattened…
There are a lot of common concepts:
immutable collection,
collection view,
strict/non strict collection,
collection builders
same patterns in Guava and Scala Collection API.
So what is the difference? Is both library are consistent with…
Let's consider a simple mapping example:
val a = Array("One", "Two", "Three")
val b = a.map(s => myFn(s))
What I need is to use not myFn(s: String): String here, but myFn(s: String, n: Int): String, where n would be the index of s in a. In…
Coming from a Java background, I'm used to the common practice of dealing with collections: obviously there would be exceptions but usually code would look like:
public class MyClass {
private Set mySet;
public void init() {
…
I'm working with a map in Scala and doing the usual "if there's no value associated with a key, create it, put it in the map and return it":
def alphaMemory(key : AlphaMemoryKey) = {
var am = map.getOrElse(key, null)
if(am == null) {
…
I need to find the number of (key , value) pairs in a Map in my Scala code. I can iterate through the map and get an answer but I wanted to know if there is any direct function for this purpose or not.
I have an array of strings. What's the best way to turn it into an immutable set of strings?
I presume this is a single method call, but I can't find it in the scala docs.
I'm using scala 2.8.1.
Is there an equivalent of Nil for Set in scala?
I tried using Nil as a value for Set, but I got an error (expected since the type of Nil is List)
Thanks
Scala 2.9 introduced parallel collections. They are a really great tool for certain tasks. However, how do they work internally and am I able to influence the behavior/configuration?
What method do they use to figure out the optimal number of…
How do I convert java.util.Map[String, Object] to scala.collection.immutable.Map[String, Any], so that all values in the original map (integers, booleans etc.) are converted to the right value to work well in Scala.
I have a List
val family=List("1","2","11","12","21","22","31","33","41","44","51","55")
i want to take its first n elements but the problem is that parents size is not fixed.
val familliar=List("1","2","11") //n=3
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 (using…
I'm using some Scala library from my Java code. And I have a problem with collections. I need to pass scala.collection.immutable.Map as a parameter of a method. I can convert or build immutable.Map from my Java code but I do not know how to do it.…