All Questions
Tagged with scala scala-collections
1,616
questions
1
vote
1
answer
58
views
When scala.collection.TraversableLike#head may returns different results in scala?
here is quote from documentation:
elects the first element of this traversable collection. Note: might return different results for different runs, unless the underlying collection type is ordered.
...
3
votes
2
answers
236
views
How to properly use collection factories in scala 2.13?
Something like this:
implicit class PairOps[A, B, C[X] <: Iterable[X]](val c: C[(A,B)]) extends AnyVal {
def swap = c.map { case (a, b) => (b, a) }
}
Kinda works ... except that val foo: ...
3
votes
2
answers
441
views
Is there a Scala 3 specific standard library or is it just inherited from Scala 2?
Is it the case that Scala 3 uses all the collections from Scala 2 standard library? (What elements Scala "standard library" consists of?)
Is there any Scala 3 specific "standard library&...
-2
votes
2
answers
116
views
Optimal way to find neighbors of element of collection in circular manner
I have a Vector and I'd like to find neighbors of given element.
Say if we have Vector(1, 2, 3, 4, 5) and then:
for element 2, result must be Some((1, 3))
for element 5, result must be Some((4, 1))
...
0
votes
2
answers
370
views
How to remove key value from map when keys are store in list in scala
I have list of keys and map following:
val keys = List("key1", "key2", "key5")
Map("key1" -> 1, "key2" -> 2, "key3" ->3, "...
1
vote
1
answer
120
views
Dedup List of case class
I have a list of case class :
case class MyClass(id1: String, id2: String, nb: Int)
val myList = List(
MyClass("id1", "id2", 3),
MyClass("id3", "id4", 4),
...
0
votes
1
answer
151
views
View vs LazyList
val patterns = Seq(
"the name and age are ([a-z]+), ([0-9]+)".r,
"name:([a-z]+),age:([0-9]+)".r,
"n=([a-z]+),a=([0-9]+)".r
)
def transform(subject: String): Option[...
1
vote
3
answers
302
views
Filter scala collection of objects with custom logic
I need to filter a collection of objects (already sorted by, let's say, property A) removing items in which property B is out of order (marked in bold below):
(Set of Tuples for simplicity)
case 1:
...
1
vote
1
answer
479
views
Scala : How to group by key and sum the values up in scala and return the list in expected return type
I am trying to group by key and sum the values up in scala!
But when I perform the below operation, I get the return type as List[(String, Long)] instead of List[InputRecord]
case class InputRecord(...
2
votes
1
answer
952
views
Filter array values during aggregation in spark dataframe
I am performing an aggregation on the following dataframe to get a list of advertisers with array of brands
+------------+------+
|advertiser |brand |
+------------+------+
|Advertiser 1|Brand1|
|...
-1
votes
1
answer
506
views
How to use a variable named 'type' in Scala class definition? [duplicate]
I have to create a class that in its definition contains a variable named 'type', for example like this:
case class testEntity (
type: String,
val: String
)
Is there any possible to do that?
3
votes
2
answers
388
views
How to sort 'Map' values in Scala against multiple factors?
I have a Map (datatype) with the following data structure:
var timePassedCamerasetB = mutable.Map.empty[String, Time];
It contains a String and a 'Time' object. The 'Time' object is made up from my ...
1
vote
2
answers
129
views
What is the best way to return a view to an ArraySeq?
Ideally when working from an IndexedSeqView over an ArraySeq, there should be only one array copy (or at least only one new array allocated) when converting the view back to an ArraySeq after some ...
0
votes
1
answer
2k
views
wrappedArray$ofRef cannot be cast to scala.collection.immutable.Seq
I'm trying to convert some Python code to Scala.
Python code:
def col_c(o_row_ids,n_row_ids):
o_set=set(o_row_ids)
n_set=set(n_row_ids)
if o_set=n_set
return "in"
...
0
votes
1
answer
461
views
Close GCP SecretManagerServiceClient after getting secrets from it
How can I close the client in the following code:
object GoogleSecret {
def apply(
project: String,
version: String = SecretVersion,
credentials: ...