In the article written by Daniel Korzekwa, he said that the performance of following code:
list.map(e => e*2).filter(e => e>10)
is much worse than the iterative solution written using Java.
Can anyone explain why? And what is the best solution for…
I have reached this far:
implicit def collectionExtras[A](xs: Iterable[A]) = new {
def zipWith[B, C, That](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: CanBuildFrom[Iterable[A], C, That]) = {
val builder = cbf(xs.repr)
val (i, j) =…
In Scala I would like to be able to write
val petMap = ImmutableMultiMap(Alice->Cat, Bob->Dog, Alice->Hamster)
The underlying Map[Owner,Set[Pet]] should have both Map and Set immutable. Here's a first draft for ImmutibleMultiMap with companion…
Let's say I have a list:
val list = List(1, 2, 3, 4, 5)
I want to replace all/first items that satisfy a predicate, I know the following way to do it: (e.g. replace any number that is even with -1)
val filteredList = list.zipWithIndex.filter(_._2 %…
I can do this quite easily, and cleanly, using a for loop. For instance, if I wanted to traverse a Seq from every element back to itself I would do the following:
val seq = Seq(1,2,3,4,5)
for (i <- seq.indices) {
for (j <- seq.indices) {
…
I am new to this authentication area. I searched a lot but was not able to find a way to authenticate the REST calls made to the Play server. What are the various ways and best practice?
How to obtain an Array[io.BufferedSource] to all files that match a wildcard in a given directory ?
Namely, how to define a method io.Source.fromDir such that
val txtFiles: Array[io.BufferedSource] = io.Source.fromDir("myDir/*.txt") // ???
Noticed…
I'm looking for a very simple example of subclassing a Scala collection. I'm not so much interested in full explanations of how and why it all works; plenty of those are available here and elsewhere on the Internet. I'd like to know the simple way…
How well to scala parallel collection operations get along with the concurrency/parallelism used by Akka Actors (and Futures) with respect to efficient scheduling on the system?
Actors' and Futures' execution is handled by an ExecutionContext…
Why is the method get defined in Option and not in Some?
One could apply pattern matching or use foreach, map, flatMap, getOrElse which is preferred anyway without the danger of runtime exceptions if None.get is called.
Are there really cases where…
I wrote a method that accepts objects of all subclasses of Seq[String]. Unfortunately it won't accept an object of the type Array[String]. Is Array[String] not a subclass of Seq[String]?
scala> def test[T <: Seq[String]](x: T) = {}
test: [T <:…
Why does the immutable version of the ListMap store in ascending order, while mutable version stores in descending order?
Here is a test that you can use if you got scalatest-1.6.1.jar and junit-4.9.jar
@Test def StackoverflowQuestion()
{
…
I need to build a sequence of objects that are loaded from an external resource. This loading being an expensive operation needs to be delayed until the time the objects are needed. After the collection is built, I need an indexed access to the…