Questions tagged [scala-collections]

Collection library for Scala Programming Language

Related Tags:

1639 questions
0
votes
1 answer

Putting object of scala.collection.iterator to the scala class constructor

I have a scala class: Rts.scala class Rts(buffer:Iterator[Tse]) extends Ts { //Some methods} Now I am trying to put Tse list to the constructor of the above class from java class: Tse tse1= new Tse(1285927200000L, 1285928100000L, 0.0); Tse tse2 =…
sjain
  • 23,126
  • 28
  • 107
  • 185
0
votes
1 answer

scala array filtering based on information of another array

I have 2 types of array like this: array one, Array(productId, categoryId) (2, 423) (6, 859) (3, 423) (5, 859) and another array Array((productId1, productId2), count) ((2, 6), 1), ((2, 3), 1), ((6, 5), 1), ((6, 3), 1) I would…
Le Kim Trang
  • 369
  • 2
  • 5
  • 17
0
votes
1 answer

Instantiating scala collections via their apply method with scala reflection

I have a tool that is trying to build instances of sub-classes of various scala collections, for example scala.collection.Seq. I don't know in advance what specific class should be built, so I am trying to use reflection to get the apply method in…
nh13
  • 1
  • 1
0
votes
3 answers

Scala map with implicit conversion

I have a Scala case class and a corresponding Java class. I've declared an implicit conversion from Scala class to Java class. Now I have a Scala collection of Scala classes, and I want to convert them to Scala collection of Java classes. Is it…
Haspemulator
  • 11,050
  • 9
  • 49
  • 76
0
votes
1 answer

Delete first element of List in Scala

I am trying to use a recursive function to go through each element in a List[Char], to check the number of occurrences of an element. I know there are easier ways and possibly even functions to do this, but would there be any way to delete just the…
user3160152
  • 51
  • 1
  • 5
  • 12
0
votes
1 answer

Type mismatch scala in Fold method

I am learning Scala and I'm having some troubles to write a simple reducer function. I want to count how many times a value appear in a list. Thus, I wrote a reducer/folding function which takes an immutable map as initial value, and then iterates…
Giuseppe Pes
  • 7,772
  • 3
  • 52
  • 90
0
votes
4 answers

How to combine elements of multiple lists in scala

I am new to Scala. I have three List. List("XX", None,None,None) List( None,"YY",None,None) List(None,None,None, "ZZ") I need to merge these list to create a single list which should look like List("XX","YY",None,"ZZ") Is there any way in scala…
Amitabh Ranjan
  • 1,500
  • 3
  • 23
  • 39
0
votes
1 answer

Convert to Map from list in Gatling

I need to form this: { “item” : “hardcoded_value”, “item2” : “hardcoded_value”, “item3” : “hardcoded_value”, } In the exec block I am trying: // list with items [“item1”, “ item2”, “ item3”] val theList = session("itemNames").as[List[String]] val…
daman
  • 309
  • 2
  • 5
  • 13
0
votes
1 answer

Behavior of map() on Options

Im trying to map a JSONObject instance into an actual instance through Play Combinators. I am able to get the desrialization work correctly. The question is on the behavior of how map() works on an Option[JSONObject]. Option1: jsonVal:…
broun
  • 2,483
  • 5
  • 40
  • 55
0
votes
1 answer

Scala :: Unable to get the output in command prompt

object ScalaTest{ def main (args: Array[String]){ var i =0 while(i<=10){ println(i) i +=1 } } } When i do c:\ Scalac ScalaTest.scala \\ it goes to the next line but c:\ Scala ScalaTest.scala…
StandForTheRight
  • 135
  • 3
  • 14
0
votes
1 answer

Why is SortedMap with default value not sorted anymore?

Is there a reason for a SortedMap with a default value becoming a regular unsorted Map? scala> val a = scala.collection.immutable.SortedMap(1 -> "uno", 3 -> "tres", 2 -> "dos") a: scala.collection.immutable.SortedMap[Int,String] = Map(1 -> uno, 2 ->…
Roberto Bonvallet
  • 31,943
  • 5
  • 40
  • 57
0
votes
1 answer

how to reparameterize collection type

I want to define a transformation of a generic collection. def transform[S<:GenIterable[T],T](s:S):S = s.zipWithIndex This throws: type mismatch; found : scala.collection.GenIterable[(T, Int)] required: S I have to declare S as a parameterized…
0
votes
1 answer

How to split RDD of (String, Array[String]) into RDD of (String, String) for each item in array?

I have a PairRDD in the form RDD[(String, Array[String])]. I want to flatten the values so that I have an RDD[(String, String)] where each of the elements in the Array[String] of the first RDD become a dedicated element in the 2nd RDD. For instance,…
Carsten
  • 1,912
  • 1
  • 28
  • 55
0
votes
1 answer

best way read a file content and find pattern in a given list of files

I have a list of files names (nearly 400 000). I need to parse each file's content and find a given string pattern. Can any one help me best way to boost my searching process(I'm able to process the content in 90 seconds). Here is the piece of code…
Puneeth Reddy V
  • 1,538
  • 13
  • 28
0
votes
1 answer

How to idiomatically turn a Seq of tuples into a Map in scala?

I have this list { 1,1 1,2 2,1 } and I want to turn it into this map { 1 -> (1,2) 2 -> (1) } What I tried so far: val list = List((1,1),(1,2),(2,1)) var map: Map[Int, Seq[Int]] = Map() for (e <- list) { if (map contains e._1) map…
gurghet
  • 7,591
  • 4
  • 36
  • 63