Environment : Scala 2.10+
IDE : Eclipse Kepler
I have a line
NAME=bala AGE=23 COUNTRY=Singapore
How can I get it as a map
Map(NAME -> bala, AGE -> 23, COUNTRY -> Singapore)
import scala.collection.JavaConversions._
val m = new java.util.LinkedHashMap[String,Int]
val s: scala.collection.mutable.Map[String,Int] = m.asInstanceOf[scala.collection.mutable.Map[String,Int]]
returns the following…
I'd like to know if there a elegant way to achieve something like that:
val l = Stream.from(1)
val parts = l.some_function(3) //any number
parts.foreach( println(_) )
> 1,4,7,10...
> 2,5,8,11...
> 3,6,9,12...
Actually I need such operation on…
I have this function to convert an Array to a ParArray, giving the number of threads as parameter:
def parN[T](collection: Array[T], n: Int) = {
val parCollection = collection.par
parCollection.tasksupport = new ForkJoinTaskSupport(
…
I have a member variable in a class:
val options = mutable.LinkedList[SelectOption]()
I latter then populate this list from the database.
At some point I want to refresh the list. How do I empty it?
In java:
options.clear();
Is there an equivalent…
Instead of xs map f map g it's more efficient to write xs map { x => g(f(x)) }, and similarly for multiple filter operations.
If I have two or more flatMaps in a row, is there a way to combine them into one, that's maybe more efficient? e.g.
def…
In the scaladoc, BitSet is defined as extending Set[Int]. So I thought using a BitSet as in instance of Set[Int] would work, but I get a type mismatch:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
scala>…
I am trying to write a generic fill method, and following is what I have come up with so far:
scala> import collection.generic.{GenericTraversableTemplate => GTT}
import collection.generic.{GenericTraversableTemplate=>GTT}
scala> import…
I have following simple code
def fib(i:Long,j:Long):Stream[Long] = i #:: fib(j, i+j)
(0l /: fib(1,1).take(10000000)) (_+_)
And it throws OutOfMemmoryError exception.
I can not understand why, because I think all the parts use constant memmory…
Total newbie question here...Today while trying to calculate sum of a list of integers(actually BitSet), I ran into overflow scenarios and noticed that the return type of(sum/product) is Int. Are there any methods in Range/List to sum up or say…
I have two huge (as in millions of entries) sets (HashSet) that have some (<10%) overlap between them. I need to merge them into one set (I don't care about maintaining the original sets).
Currently, I am adding all items of one set to the other…
Scala's collection library contains the forwarders IterableForwarder, TraversableForwarder, SeqForwarder and proxies like IterableProxy, MapProxy, SeqProxy, SetProxy, TraversableProxy, etc. Forwarders and proxies both delegate collection methods to…
Let's consider following trait:
sealed trait AB
case class A(a: Int) extends AB
case class B(b: Int) extends AB
I am trying to collect to limit a collection to specific subclass.
If I try to collect, matching individual components and reassembling…
This could be a very silly question, but I am not able to understand the difference even after scratching my head for a long time.
I am going through the page of scala generics: https://docs.scala-lang.org/tour/generic-classes.html
Here, it is said…