I've a three-level data structure (indentation and line breaks for readability):
scala> import scala.collection.mutable.Map
import scala.collection.mutable.Map
scala> val m = Map("normal" -> Map("home" -> Map("wins" -> 0, "scores" -> 0),
…
Assume we have a side-effecting "producer" function f: () => Option[T] which returns a Some when repeatedly called until a future point at which it will forever return None. (e.g. a wrapped Java API producing null at EOF might well have this sort of…
I have been reading some posts and was wondering if someone can present a situation on when a TrieMap would be preferable to using a HashMap.
So essentially what architecture decision should motivate the use of a TrieMap?
For any given String, for instance
val s = "abde"
how to insert a character c: Char at position 2, after b ?
Update
Which Scala collection to consider for multiple efficient insertions and deletions at random positions ? (Assuming that a String…
I just stumbled on one of Tony Morris' blog-posts about Java and a fundamental problem with the language: that of defining a bespoke equality-relation for a collection. This is something that I think is a big deal and wondered whether there was some…
I'm implementing a generic algorithm to return a collection based on two other collections.
The problem can be simplified to
def add[Repr <: Traversable[_]](coll1: Repr, coll2: Repr) = coll1 ++ coll2
The problem occurred when I applied the…
I'm using scala 2.9.1, when I try this code:
import scala.collection.mutable
val a = mutable.Set(1,2,3,4,7,0,98,9,8)
a.foreach(x => { println(x); a.remove(x) })
the result was something like
0
98
2
1
4
3
8
which did not list all the elements of a.…
Suppose you have
val docs = List(List("one", "two"), List("two", "three"))
where e.g. List("one", "two") represents a document containing terms "one" and "two", and you want to build a map with the document frequency for every term, i.e. in this…
I want to implement a tree in Scala. My particular tree uses Swing Split panes to give multiple views of a geographical map. Any pane within a split pane can itself be further divided to give an extra view. Am I right in saying that neither TreeMap…
Looking at the code in JavaConversions and JavaConverters, I am unsure which the "correct" way (with 2.10) to convert between Java and Scala collections (in either direction) is.
There seem to be lots of @deprecated annotations.
Has a definitive…
I'm having some trouble with this code.
It's supposed to be an OperationTree with Elements BinaryOperations and UnaryOperations.
The method eval does the evaluation and looks up the variables in a map.
Here's the code
1 import…
I am new to Scala and I just learned that LazyList was created to replace Stream, and at the same time they added the .view methods to all collections.
So, I am wondering why was LazyList added to Scala collections library, when we can do…
I wrote the function to find longest common subsequence (LCS). For example, for two sequences of chars BANANA and ATANA it returns AANA. Implementation is naive inefficient adaptation of recursive algorithm, but it is irrelevant for purpose of this…
I am trying to define a set of "LazyChains" that will be used to process incoming messages at a future time. I want the API of the LazyChains to be indistinguishable from the Scala collections APIs (ie: Seq, Stream, etc). This would allow me to…
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("alf.kristian@gmail.com")))
val fredrik =…