Questions tagged [scala-collections]

Collection library for Scala Programming Language

Related Tags:

1639 questions
0
votes
1 answer

How do I create an infinite Queue from Stream in Scala?

I want an infinite queue that is backed by an infinite stream in Scala. This feels simple enough but I just can't find how to do this. I.e. Stream.from(0).toQueue // Except that there is no method "toQueue"
BasilTomato
  • 1,071
  • 1
  • 8
  • 14
0
votes
4 answers

Better safe get from an array in scala?

I want to get first argument for main method that is optional, something like this: val all = args(0) == "all" However, this would fail with exception if no argument is provided. Is there any one-liner simple method to set all to false when args[0]…
igr
  • 10,199
  • 13
  • 65
  • 111
0
votes
2 answers

How can I define a class that is almost the same as List

In Scala, suppose I would like a class that is just like List[String] except for a few methods, for example toString. What I have now is case class FQN(val names : List[String]) extends LinearSeq[String] { def this( params : String* )…
Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45
0
votes
1 answer

How do I get an item in a list that matches a certain condition?

I have the following sample code : package models import java.util.concurrent.atomic.AtomicInteger import scala.collection.mutable.ArrayBuffer case class Task(id: Int, label: String) object Task { private val buffer = new ArrayBuffer[Task] …
Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
0
votes
1 answer

Scala inferring wrong type when using Seq append operator "+:"

I'm still pretty new to Scala. I'm having trouble trying to append two Sequences together because the compiler is complaining about the type of the Seq. I would like to start with a Seq[String] var and replace it with the addition of two…
harschware
  • 13,006
  • 17
  • 55
  • 87
0
votes
3 answers

Counting occurrences of elements without .groupBy

I need to count occurrences of element in list. List looks like this: List[(String, String, Int)] - list of (String, String, Int) tuples. Example: List(("Gregor", "Math", 6), ("Mark", "Math", 33), ("Gregor", "IT", 44), ("Jane", "Math", 3), …
akcza
  • 43
  • 1
  • 1
  • 6
0
votes
2 answers

How to get combined lists from two list using scala?

I have two lists val list1 = List((List("AAA"),"B1","C1"),(List("BBB"),"B2","C2")) val list2 = List(("AAA",List("a","b","c")),("BBB",List("c","d","e"))) I want to match first element from list2 with first element of list1 and get combined list. I…
Neo-coder
  • 7,715
  • 4
  • 33
  • 52
0
votes
1 answer

how to sort Map[Int,Map[String,String]] according to inner map value

How to sort Map[Int,Map[String,String]]? var data=Map(1416479696353 -> Map(name -> You,savePoint -> 4), 1416479788969 -> Map(name -> You, savePoint -> 9), 1416479801372 -> Map(name -> govind,savePoint -> 10)) i want to sort above map according to…
Govind Singh
  • 15,282
  • 14
  • 72
  • 106
0
votes
3 answers

Extract string of "length x breadth" into different arrays

I have a string with with multiple length and breadth in the format length x breadth separated by commas like 300x250, 720x220, 560x80 I will like to convert this into two separate arrays one containing only length and another only…
mohit
  • 4,968
  • 1
  • 22
  • 39
0
votes
1 answer

Scala two list match data

First List data as below List(("A",66729122803169854198650092,"SD"),("B",14941578978240528153321786,"HD"),("C",14941578978240528153321786,"PD")) and second list contains data as below…
Pradip Karad
  • 1,377
  • 2
  • 9
  • 8
0
votes
1 answer

How expensive is the call to result() for a builder of immutable containers in Scala?

I plan to populate an immutable HashMap inside a scala class instance using a builder, then expose the hashMap with a method calling result() on the builder. Is this call very cheap or is it worth saving this result in a member field for faster…
michael meyer
  • 169
  • 2
  • 9
0
votes
2 answers

separate two lists by difference in elements in them

If I have val incomingIds : List[Int] = .... val existingIds : List[Int] = //this makes db calls and find existing records (only interested in returning ids) Now next I want to compare incomingIds with existingIds in a following way say I have val…
user2066049
  • 1,371
  • 1
  • 12
  • 26
0
votes
2 answers

Scala add items to ListBuffer inside recursive method

Im trying to add items to a ListBuffer (or any other structure ?) basically i'm trying to create a list of PostMD objects by using this method. def getData(url: String, userID: String): ListBuffer[PostMD] = { val chunk: JsValue =…
MIkCode
  • 2,655
  • 5
  • 28
  • 46
0
votes
1 answer

Understanding the code that creates a mutable.Map with mutable.MultiMap

Can anyone explain what's going on in this dense code: val m = new mutable.HashMap[Int, mutable.Set[String]] with mutable.MultiMap[Int, String]
lolski
  • 16,231
  • 7
  • 34
  • 49
0
votes
1 answer

How to generate rules from a string values in scala?

I want to make rules from strings. for example, My strings are: Ball Cat Egg Cat Egg Apple Cat Ball Egg Ball Cat I want the rules as, Ball -> Cat Egg Cat -> Ball Egg Egg -> Ball Cat Ball Cat -> Egg Cat Egg -> Ball Ball Egg -> Cat Cat -> Egg Egg ->…
rosy
  • 146
  • 2
  • 14
1 2 3
99
100