Questions tagged [scala-collections]

Collection library for Scala Programming Language

Related Tags:

1639 questions
0
votes
3 answers

Signature of sorted method in SeqLike

I don't understand the purpose for the signature of the sorted method within the SeqLike trait: def sorted[B >: A](implicit ord: Ordering[B]): Repr More precise, I don't get: The reason for B>:A What does Repr mean? Perhaps you can shed some…
Adrian
  • 155
  • 9
0
votes
1 answer

Gatling :- Read Multiple JSON Payload from single file

I'm making many HTTP request with JSON Payload and I'm reading one file for every single request to get JSON Payload as below. postPayload1 = val postPayload = ElFileBody("Test_case1.json") val TC1 = feed(accountNumberFeeder1) …
Swapnil Kotwal
  • 5,418
  • 6
  • 48
  • 92
0
votes
4 answers

How can I capture multiple variables using pattern matching?

For example: List(1,2,3,4) match { case List(x: Int, y: Int, *rest) => println(rest) // i want to get List(3,4) } _* can match multiple variables but do to seem to be able to capture them. Thanks!
Chi Zhang
  • 771
  • 2
  • 8
  • 22
0
votes
2 answers

How do you remove every instance of a list from another list?

I have a list val l = List(1,2,3,2,6,4,2,3,4,2,1,3,6,3,2) and I want to remove every instance of a particular sequence such as (2,3) So the desired output is... List(1,2,6,4,4,2,1,3,6,3,2) What is the easiest/most idiomatic way to accomplish this…
Ryan Stull
  • 1,056
  • 14
  • 35
0
votes
0 answers

How to split a collection into groups using the calculation of member as a predicate

I have a method that collect the consecutive number with the difference of no more than some number (2 in my example). This code is working just fine but it does zipping every time it is called, so I wonder if there is any better solution to this…
0
votes
0 answers

collect a list of Rows to a dataframe in Scala

I have a List[org.apache.spark.sql.Row] which I got from a ListBuffer[org.apache.spark.sql.Row]() How do I turn this into a dataframe? obviously .toDF (or RDD) does not work...
Zahiro Mor
  • 1,708
  • 1
  • 16
  • 30
0
votes
2 answers

Implicit conversion between java and scala collections using JavaConversions

I merged a scala Set of scala Maps using a generic function def mergeMaps[A, B](ms: Set[Map[A, B]])(f: (B, B) => B): Map[A, B] = (Map[A, B]() /: (for (m <- ms; kv <- m) yield kv)) { (a, kv) => a + (if (a.contains(kv._1)) kv._1 -> f(a(kv._1),…
rrrocky
  • 696
  • 1
  • 11
  • 27
0
votes
1 answer

Reduce a List of Map of Tuples

I have the following variable val x1 = List((List(('a',1), ('e',1), ('t',1)),"eat"), (List(('a',1), ('e',1), ('t',1)),"ate")) I want to get a List(Map -> List) that will look something like the following. The idea is to group words b the…
borarak
  • 1,130
  • 1
  • 13
  • 24
0
votes
2 answers

java.util.Set conversion to scala.immutable.Map

I have a Set[Set[String], Set[String]] of java.util.Set type which I want to convert to scala.immutable.Map[String, scala.immutable.Set[String]]. The mapping is like each element of the first set inside the outermost set maps to the second set of…
rrrocky
  • 696
  • 1
  • 11
  • 27
0
votes
2 answers

Concatenating multiple lists in Scala

I have a function called generateList and concat function as follows. It is essentially concatenating lists returned by the generateList with i starting at 24 and ending at 1 def concat(i: Int, l: List[(String, Int)]) : List[(String, Int)] = { …
Saqib Ali
  • 3,953
  • 10
  • 55
  • 100
0
votes
2 answers

Sequence map throws an error: NoSuchElementException: next on empty iterator

This is my very first try for scala in play framework. What I really want to achieve is to take every first word from sentences in a paragraph. This is the code that throws an error Text is mutable.Seq[String] someText.flatMap(_ split "[.?!]") …
muhrifqii
  • 19
  • 2
  • 9
0
votes
1 answer

Scala wrapper API for java API

I am new to Scala and I need to have a scala wrapper for my Java API I have three Java Interfaces public interface Client { Future execute(App app); } public interface App extends Serializable{ T process(AppContext…
user3451476
  • 297
  • 1
  • 4
  • 17
0
votes
0 answers

Scala's Range with Float performance does not meet expectations

I typed the code below in scala console and get the return: scala> 1.0F to 5.0F by 1.3F res10: scala.collection.immutable.NumericRange[Float] = NumericRange(1.0, 2.3, 3.6, 4.8999996) why the ret is NumericRange(1.0, 2.3, 3.6, 4.8999996) instead of…
zwb
  • 886
  • 2
  • 8
  • 21
0
votes
1 answer

Scalatra throwing null pointer exception with java 8

I am running a web application with Scala version 2.9.0 and Scalatra version 2.1.0-SNAPSHOT. I build the application with Java 1.6. It runs fine when I run it with Java 1.7 but fails when ran with Java 1.8 with this error. What can be the issue? It…
RckR
  • 45
  • 4
0
votes
1 answer

Scala wait of list of future to execute

Hi I am trying to process data in a file. This the code I am using below. I have a list of Futures and trying to get the output from these futures. Everything is fine but the last line of return is executing before OnSuccess. How can I change that…
abhishek
  • 31
  • 1
  • 6