we have a project written in Java. It is a maven project, that has jsp pages and a lot of java code:
servlets for handling user requests and dealing out responses.
classes of logic used by servlets in order to process the required logic.
classes of…
I'm using a library (JXPath) to query a graph of beans in order to extract matching elements. However, JXPath returns groups of matching elements as an instance of java.lang.Iterator and I'd rather like to convert it into an immutable scala list.…
I've tried different collections in Scala to sum it's elements and they are much slower than Java sums it's arrays (with for cycle). Is there a way for Scala to be as fast as Java arrays?
I've heard that in scala 2.8 arrays will be same as in java,…
Given the following data model:
sealed trait Fruit
case class Apple(id: Int, sweetness: Int) extends Fruit
case class Pear(id: Int, color: String) extends Fruit
I've been looking to implement a segregate basket function which for the given…
Is there a Round Robin Queue available in Scala Collections?
I need to repeatedly iterate a list that circles through itself
val x = new CircularList(1,2,3,4)
x.next (returns 1)
x.next (returns 2)
x.next (returns 3)
x.next (returns 4)
x.next…
Scala's Map and Set define a + operator that returns a copy of the data structure with a single element appended to it. The equivalent operator for Seq is denoted :+.
Is there any reason for this inconsistency?
I'd like to link 2 columns of unique identifiers and be able to get a first column value by a second column value as well as a second column value by a first column value. Something like
Map(1 <-> "one", 2 <-> "two", 3 <-> "three")
Is there such a…
I'm working through Cay Horstmann's Scala for the Impatient book where I came across this way of updating a mutable map.
scala> val scores = scala.collection.mutable.Map("Alice" -> 10, "Bob" -> 3, "Cindy" -> 8)
scores:…
I have the following code:
private lazy val keys: List[String] = obj.getKeys().asScala.toList
obj.getKeys returns a java.util.Iterator
Calling asScala, via JavaConverers (which is imported) according to the docs..…
Constructing scala.collection.Map from other collections, I constantly find myself writing:
val map = Map(foo.map(x=>(x, f(x)))
However, this doesn't really work since Map.apply takes variable arguments only - so I have to write:
val map =…
For a Scala List[Int] I can call the method max to find the maximum element value.
How can I find the index of the maximum element?
This is what I am doing now:
val max = list.max
val index = list.indexOf(max)
When I evaluate a for in Scala, I get an immutable IndexedSeq (a collection with array-like performance characteristics, such as efficient random access):
scala> val s = for (i <- 0 to 9) yield math.random + i
s:…
Is there a reason why there is no implicit Ordering for Lists in Scala?
val lists = List(List(2, 3, 1), List(2, 1, 3))
lists.sorted
error: could not find implicit value for parameter ord: Ordering[List[Int]]
EDIT
Yes, my question is why there is…