Questions tagged [scala-collections]

Collection library for Scala Programming Language

Related Tags:

1639 questions
0
votes
1 answer

What's the easiest way to circumvent [SI-6976] in scala 2.10 for primitive collection pattern matching?

I have a simple function: implicit class ArrayView[A](self: Array[A]) { def filterByType[B <: A: ClassTag]: Array[B] = { val ctg = implicitly[ClassTag[B]] val runtimeClazz = ctg.runtimeClass self.flatMap{ v => …
tribbloid
  • 4,026
  • 14
  • 64
  • 103
0
votes
1 answer

Scala - map a value from a Map to another Map

I've a requirement to map a field in my RDD to another field from another map UserDAO.users I've tried to figure out the mapping here but can't return the username yet. I'm getting this in the updated map when I do a foreach print…
Philip K. Adetiloye
  • 3,102
  • 4
  • 37
  • 63
0
votes
1 answer

Scala Overloading Issue

If I have a java.util.Map[String,Java.util.Map] for the first call, correct overloaded method is called: toScala(java.util.Map[_,_]). But in the mapValues invocation, function toScala(other:Any) is called. How to avoid this? I would be calling…
bugs
  • 1
  • 2
0
votes
1 answer

Scala sum of the arrays contained in an array

I have defined a function that receives an array of arrays. I want to get the sum of all arrays. My question is how to make that sum. def suma[T](args: WrappedArray[T]*)(implicit n: Numeric[T]) = { args.transpose.map(_.sum) } def sum[T](arr:…
nest
  • 347
  • 2
  • 5
  • 17
0
votes
2 answers

High performance Scala/Java collection needed

I am looking for a Scala (or Java/Guava) collection that supports O(1) access to (and ideally removal of) its minimum element as well as O(log n) insertion and removal of arbitrary elements. Thoughts?
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
0
votes
1 answer

Scala 2.10: Convert mutable Map of ListBuffer to readonly datastructure

I am using the following code to traverse directories and adding files to a mutable Map of mutable ListBuffer. The key is the directory name and the values are the list of files under that directory. def WalkDir(path:String):…
Neel
  • 9,913
  • 16
  • 52
  • 74
0
votes
2 answers

How do you create a Scala collection of content in a Play template?

I'm sure I'm missing the obvious but is there a way to create a collection of Html objects to pass to a Play template like @(title: String)(content: Seq(Html))? I am trying to dynamically generate a group of tab pages where each Html object is the…
0
votes
1 answer

How do I modify this library design so that Scala will infer the correct builder implicit argument?

Below I have a simplified version of a library I'm working on. I modeled this after the scala collection library's CanBuildFrom trait, since my requirements are similar. However, I can't quite get it to infer the correct builder to use in all…
Nimrand
  • 1,748
  • 2
  • 16
  • 29
0
votes
2 answers

Scala: Creating singleton object by calling constructor

I want to create a singleton object for my application , but i want to initialize it from another object. For ex : object A{ val x = 10 val b = B(x) } object B(y:Int){ var z = y } But this would not work , since object doesnt have constructor.…
Alok
  • 1,374
  • 3
  • 18
  • 44
0
votes
0 answers

spark job freeze when started in ParArray

I want to convert a set of time-serial data to Labeledpoint from multiple csv files and save to parquet file. Csv Files are small, usually < 10MiB When I start it with ParArray, it submit 4 jobs a time and freeze . codes here val idx =…
skywalkerytx
  • 244
  • 2
  • 14
0
votes
1 answer

Scala data structure for storing multiple variable which can be used in collection.contains or collection.exisits

I have a requirement ,where i have multiple tuples coming in. For eg: (a1, b1) (a2, b2) (a3, b3) I need to store these values in datastructure and create a collection of these. Next I will get another tuple as input (an, bn) and i…
Alok
  • 1,374
  • 3
  • 18
  • 44
0
votes
1 answer

A (strictly) `Growable` mutable `Seq`

I need a (mutable) Seq that is only Growable. I do not need to update any index or shrink the collection or transform it (or any other form of mutation), Just grow it (+=) and I want to actively protect the collection from other mutations. The…
Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68
0
votes
1 answer

Scala : How to find types of values inside a scala nested collection

consider the following variables in scala : val nestedCollection_1 = Array( "key_1" -> Map("key_11" -> "value_11"), "key_2" -> Map("key_22" -> "value_22")) val nestedCollection_2 = Map( "key_3"-> ["key_33","value_33"], "key_4"->…
0
votes
1 answer

Runtime of tail and init on List

if I have the following with ls an instance of scala.collection.immutable.List : will ls.init make a copy of the first n-1 elements of ls and then give this copy back thus yielding a runtime of theta of n-1(because of the copy runtime)? Does…
Simonlbc
  • 591
  • 1
  • 4
  • 16
0
votes
1 answer

Optional tuples to Map in Scala

If I have a List of tuples, I can convert to a map with toMap: val x = (3 -> 3) List(x).toMap and I get scala.collection.immutable.Map[Int,Int] = Map(3 -> 3) If I have a List of Optional and try the same I would get an error: val x = Some(3 ->…
pedrorijo91
  • 7,635
  • 9
  • 44
  • 82