Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [scala-collections]

Collection library for Scala Programming Language

scala-collections
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. ...
Cherry's user avatar
  • 32.8k
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: ...
Dima's user avatar
  • 40.3k
3 votes
2 answers
444 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&...
pogurek's user avatar
  • 45
-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)) ...
Kotofey's user avatar
  • 21
0 votes
2 answers
373 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, "...
Ksheth's user avatar
  • 33
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), ...
Ben Dns's user avatar
  • 13
1 vote
1 answer
257 views

Why release fences added to Scala collections in 2.13 are enough in absence of matching acquire fences?

The process of creation of some of Scala immutable collections, most notably List, is mutable. In 2.13 the concurrency issues were addressed by adding a release fence basically to every builder. A ...
Turin's user avatar
  • 2,220
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[...
applewil's user avatar
  • 378
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: ...
CoderX's user avatar
  • 162
1 vote
1 answer
483 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(...
Sekar Ramu's user avatar
2 votes
1 answer
954 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| |...
Meesam's user avatar
  • 41
-1 votes
1 answer
508 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?
federico celadin's user avatar
3 votes
2 answers
389 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 ...
Brian's user avatar
  • 57
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 ...
kag0's user avatar
  • 5,914
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" ...
arya's user avatar
  • 436

15 30 50 per page
1
2 3 4 5
110