Questions tagged [scala-collections]

Collection library for Scala Programming Language

Related Tags:

1639 questions
0
votes
0 answers

Passing parameters to scala slick query

I am trying to pass a list of integers in the IN clause of a SQL Server JDBC query using Slick API for scala. The val stockIdsOfInterest is a list of integers that I want to pass in the IN clause. Here is my query: val stockIdsOfInterest = …
Darth.Vader
  • 5,079
  • 7
  • 50
  • 90
0
votes
1 answer

Remove and return single value from parallel, mutable map

I am wrapping a mutable parallel map in Scala and would like to remove and return a single value from the map. Current implementation is as follows... class MyContainer[O] { def remove(uuid: UUID): Option[O] = backingStore.get(uuid) match { …
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
0
votes
2 answers

How to use the GraphStream library for Scala

I tried to use the GraphStream library to find the shortest path between 2 nodes in a graph. At the end I'm able to print the edges of the path (it.foreach(println)) but I can't access one element at the time. This is the code: import…
Stefano Sandonà
  • 619
  • 3
  • 9
  • 18
0
votes
1 answer

Parallel Aggregate is not working on lists .length > 8

I'm writing a small exercise app that calculates number of unique letters (incl Unicode) in a seq of strings, and I'm using aggregate for it, as I try to run in parallel here's my code: class Frequency(seq: Seq[String]) { type FreqMap = Map[Char,…
dark_ruby
  • 7,646
  • 7
  • 32
  • 57
0
votes
1 answer

Where is the implementation of Array.map?

In Scala collections (e.g. 2.11 or 2.12), where can I find the code that gets executed when an Array is mapped? i.e. val a = Array(1,2,3) val b = a.map(_ * 5) // <--- here
mitchus
  • 4,677
  • 3
  • 35
  • 70
0
votes
1 answer

For loop issue in scala spark case

Looking to compare field by field of rdds by key and trying to populate the unmatched array fields but unable to use for loop. below code wherein for loop is commented is working for 1st field check but I wanted to use for loop to cover all fields…
chaitupadi
  • 11
  • 1
  • 4
0
votes
1 answer

Find common items in two lists (Scala)

A newbie Scala question . I'm trying to implement a function that receive two Lists ,find a common item , than make manipulation and create a new list I have a case class case class weightedFruits(fruits: Set[String], weight: Double) and two…
Toren
  • 6,648
  • 12
  • 41
  • 62
0
votes
1 answer

How to iterate over JSValue parsed from JSON String

I have a JSON String , val name : String = "["Client_2","tClient_1","Client_NB"]" I have converted the Json String to JSValue as below using play val json: JsValue = Json.parse(cells) Output of json :…
PGS
  • 1,046
  • 2
  • 17
  • 38
0
votes
1 answer

Strange behavior when creating ForkJoinTask for multithreading in Scala loop

The job is to convert the values from the src array and write the new values to the dst array. When I create ForkJoinTasks in a while loop val height: Int = 4; val numTasks: Int = 2; var tasks =…
0
votes
1 answer

Create an instance of a generic type in Scala?

I am trying my hand at a bit of generic programming with Scala and am trying to figure out how to create an instance of a class of type CC as described in the code below. I have defined the following abstract trait... /** Trait defining the…
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
0
votes
1 answer

How to make a class wrapping an immutable collection immutable in Scala?

In a previous SO post I asked about an idiomatic way to make a container class wrapping an immutable collection thread-safe. Answers that I received all involved using various flavors of read/write locks or synchronization which is not what I…
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
0
votes
1 answer

Create a SparseVector from the elements of RDD

Using Spark, I have a data structure of type val rdd = RDD[(x: Int, y:Int), cov:Double] in Scala, where each element of the RDD represents an element of a matrix with x representing the row, y representing the column and cov representing the value…
EdgeRover
  • 195
  • 1
  • 15
0
votes
3 answers

Convert Json string to map in scala

I have a JSON string, say: val json = JSONObject(Map("a" -> 1)).toString() I want to convert this json to map again. I tried: val map = json.toMap[String, Int] This gives me the following error: Error:(46, 25) Cannot prove that Char <:< (String,…
nish
  • 6,952
  • 18
  • 74
  • 128
0
votes
3 answers

Returning values which compute sum

Here is a Scala stream to calculate the Fibonacci sequence : import scala.math.BigInt object fib extends App { val fibs: Stream[BigInt] = BigInt(0) #:: BigInt(1) #:: fibs.zip( fibs.tail).map(n => { n._1 + n._2 …
blue-sky
  • 51,962
  • 152
  • 427
  • 752
0
votes
2 answers

How to sum a List[(Char,Int)] into a Map[Char,Int] in Scala?

I've got list of pairs: List(('a',3),('b',3),('a',1)) and I would like to transform it by grouping by _1 and summing _2. The result should be like Map('a'->4, 'b' -> 3) I very new to Scala so please be kind :)
Michał
  • 616
  • 1
  • 7
  • 22