I have an instance of a scala.collection.immutable.List and I want to call the map method on it, BUT from Java.
I need to supply a CanBuildFrom.
I noticed that a lot of the scala collections companion objects contain implicit CanBuildFrom instances,…
I have looked at these links
http://blog.danielwellman.com/2008/03/using-scalas-op.html
http://blog.tmorris.net/scalaoption-cheat-sheet/
I have a map of [String, Integer] and when I do a map.get("X") I get an option. I would like the following.
val…
So I've recently started learning Scala and have been using graphs as sort of my project-to-improve-my-Scala, and it's going well - I've since managed to easily parallelize some graph algorithms (that benefit from data parallelization) courtesy of…
In 'Programming in Scala, Second Edition' at page 410 you can find class Simulation which have the following method:
private def next() {
(agenda: @unchecked) match {
case item :: rest =>
agenda = rest
curtime = item.time
…
For put and get operations OpenHashMap outperform HashMap by about 5 times: https://gist.github.com/1423303
Are any cases when HashMap should be preferred over OpenHashMap?
I want following function
range((1,1), (2,2)) which return
Seq[(Int,Int)]((1,1),(1,2),(2,1),(2,2))
It is analog for one dimensional range with 1 to 2
The function should work for any scala tuple (i.e. Tuple2, Tuple3, Tuple4, ...) and be…
I've had this situation occur a number of times in the library I'm writing, and I'm not particularly satisfied with the solutions I've come up with so far.
Let's say that I have an expensive function f that takes an item of type T and returns a…
I have a collection of ints that repeat themselves in a pattern:
val repeatingSequence = List(1,2,3,1,2,3,4,1,2,1,2,3,4,5)
I'd like to section that List up when the pattern repeats itself; in this case, when the sequence goes back to 1:
val…
I tried to convert a sequential list to a parallel one in Intellij, but I get the error
Cannot resolve symbol par
on the .par method call:
import scala.collection.parallel.immutable._
...
val parList = List(1,2,3).par
According to…
Java has method in java.util.Map called compute which provides a way to update map when the key is present or absent in the map.
Does scala.collection.mutable.Map provides any similar function?
I've checked the documentation Map and HashMap but…
I was wondering if we can print the definition of a function in Scala. A function is treated as an object in Scala.
For example:
scala> val splitFunction = (value : String) => { value.split(" ")}
splitFunction: String => Array[String] =…
I have to call some Java library code that returns an untyped java.util.List and I can't seem to convert this into a Scala 2.8 list without the compiler borking with the following error:
[INFO] found : java.util.List[?0] where type ?0
[INFO] …
Adding two Set[Int] works:
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Server VM, Java 1.6.0_23).
Type in expressions to have them evaluated.
Type :help for more information.
scala> Set(1,2,3) ++ Set(4,5,6)
res0:…
As an exercise, I'd like to extend the Scala Array collection to my own OneBasedArray (does what you'd expect, indexing starts from 1). Since this is an immutable collection, I'd like to have it return the correct type when calling filter/map…
I'll start the ball rolling.
Given a sequence of elements, some of which can be contained multiple times, one typical requirement is to count them - in the form of a tally or histogram.
The oft-quoted solution…