I am trying to understand the following code but can't.
it is supposed to create a child actor for an Event if it does not exist, otherwise says that the Event exist as it as an associated child actor.
context.child(name).fold(create())(_ =>…
I have a MutableList and I want to remove an element from it but I cannot find the appropriate method. There is a method to remove element from ListBuffer like this:
val x = ListBuffer(1, 2, 3, 4, 5, 6, 7, 8, 9)
x -= 5
I am unable to find an…
I'm studying the source code of the Scala 2.8 collection classes. I have questions about the hierarchy of scala.collection.Traversable. Look at the following declarations:
package scala.collection
trait Traversable[+A]
extends…
Is it possible to remove elements from PriorityQueue?
Documentation:
http://www.scala-lang.org/api/current/index.html#scala.collection.mutable.PriorityQueue
http://www.scala-lang.org/api/current/index.html#scala.collection.Iterator
I have a PQ w…
scala> val m = Map(1 -> 2)
m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> m.map{case (a, b) => (a+ 1, a+2, a+3)}
res42: scala.collection.immutable.Iterable[(Int, Int, Int)] = List((2,3,4))
What I want is for the result type to be…
Which are the differences between scan and scanLeft ?
For instance,
(1 to 3).scan(10)(_-_)
res: Vector(10, 9, 7, 4)
(1 to 3).scanLeft(10)(_-_)
res: Vector(10, 9, 7, 4)
deliver the same result, clearly in contrast to
(1 to…
I find lots of people trying to do this, and asking about this but the question is always answered in terms of scala code. I need to call an API that is expecting a scala.collection.immutable.Map but I have a java.util.Map, how can I cleanly convert…
I wanted to write it functionally, and the best I could do was:
list.zipWithIndex.filter((tt:Tuple2[Thing,Int])=>(tt._2%3==0)).unzip._1
to get elements 0, 3, 6,...
Is there a more readable Scala idiom for this?
This is more a question of style and preference but here goes: when should I use scala.Array? I use List all the time and occasionally run into Seq, Map and the like, but I've never used nor seen Array in the wild. Is it just there for Java…
As title of this question suggests: my question is more about form (idiomatic convention) than function. Put Succinctly:
What is the semantic difference between MyCollectionLike and MyCollection?
As examples: What is the difference between…
If I want to remove the highest entry in log(n) time in Java's TreeSet, I use treeSet.pollFirst() - what is the equivalent for Scala's mutable.TreeSet class?
Anyway, what I really want is a heap-like priority queue data structure that lets me…
According to the paper on parallel collections and searching on the internet, parallel collections are supposed to work with views, but I am not clear on the difference…
I have a Traversable, and I want to make it into a Java Iterator. My problem is that I want everything to be lazily done. If I do .toIterator on the traversable, it eagerly produces the result, copies it into a List, and returns an iterator over the…
Following Scala courses on Coursera, Martin Odersky showed an example code which is:
1 to 5 map ( i => i*i )
And he said the Range gets transformed to a Vector because they share the same interface (IndexedSeq) and the result could not be…
(This is a variant to this Q&A)
Say I have this:
List( "foo", "bar", "spam" )
I want to create a Map for which the key is the length of the String and the value is a Collection of all the Strings that have that length. In other words, given the…