Questions tagged [scala-collections]

Collection library for Scala Programming Language

Related Tags:

1639 questions
13
votes
1 answer

What is the current element in a Scala DoubleLinkedList?

I'm looking at using a DoubleLinkedList. It's remove() method says "Removes the current node from the double linked list." but there are no other references to current in the page. What is the current node, how do I set it, and surely this can't be…
Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118
13
votes
1 answer

Scala SortedSet - sorted by one Ordering and unique by something else?

Say I have a set of Strings that I want to be ordered by length but unique by the normal String uniqueness. What I mean is that I that I could have more than one String of same length in the Set, but that they should be sorted by length. I want to…
Viktor Hedefalk
  • 3,572
  • 3
  • 33
  • 48
13
votes
3 answers

how to convert List(String,String) to ListMap[String,String]?

I have a list of type List(String,String) and I wanted to convert it to map. When I used toMap method I found that it does not preservers the order of data that is there in the List. However my goal is to convert the list to Map by keeping the order…
Explorer
  • 1,491
  • 4
  • 26
  • 67
13
votes
2 answers

What is the difference between Seq and IndexedSeq/LinearSeq in Scala?

In Scala Collection documentation, there is some clue to this question: Trait Seq has two subtraits LinearSeq, and IndexedSeq. These do not add any new operations, but each offers different performance characteristics: A linear sequence has…
Milad Khajavi
  • 2,769
  • 9
  • 41
  • 66
13
votes
3 answers

Creating lists and sets in Scala: What do I actually get?

If I create a Set in Scala using Set(1, 2, 3) I get an immutable.Set. scala> val s = Set(1, 2, 3) s: scala.collection.immutable.Set[Int] = Set(1, 2, 3) Q1: What kind of Set is this actually? Is it some hash-set? What is the complexity of look-ups…
aioobe
  • 413,195
  • 112
  • 811
  • 826
13
votes
2 answers

scala implicit or explicit conversion from iterator to iterable

Does Scala provide a built-in class, utility, syntax, or other mechanism for converting (by wrapping) an Iterator with an Iterable? For example, I have an Iterator[Foo] and I need an Iterable[Foo], so currently I am: val foo1: Iterator[Foo] = .... …
Landon Kuhn
  • 76,451
  • 45
  • 104
  • 130
13
votes
1 answer

How do I implement a collection in Scala 2.8?

In trying to write an API I'm struggling with Scala's collections in 2.8(.0-beta1). Basically what I need is to write something that: adds functionality to immutable sets of a certain type where all methods like filter and map return a collection…
13
votes
1 answer

How do I set the default number of threads for Scala 2.10 parallel collections?

In Scala before 2.10, I can set the parallelism in the defaultForkJoinPool (as in this answer scala parallel collections degree of parallelism). In Scala 2.10, that API no longer exists. It is well documented that we can set the parallelism on a…
JZeta
  • 153
  • 1
  • 6
13
votes
4 answers

Summing up two options

Let's say I have two optional Ints (both can be Some or None): val one : Option[Int] = Some(1) val two : Option[Int] = Some(2) My question is the following: Are there any intelligent way to sum them op using Scalas brilliant collection-methods? I…
Jens Egholm
  • 2,730
  • 3
  • 22
  • 35
13
votes
3 answers

How do I create multidimensional Vectors in Scala?

I want to work with an immutable indexed multidimensional array. The structure that makes sense is a Vector of Vectors. scala> val v = Vector[Vector[Int]](Vector[Int](1,2,3), Vector[Int](4,5,6), Vector[Int](7,8,9)) v:…
W.P. McNeill
  • 16,336
  • 12
  • 75
  • 111
13
votes
1 answer

Use case for LinkedList

This post only discusses scala.collection.mutable.LinkedList. Other implementations are not the topic of this thread. My question is: what is the use case of this class? I find it has the problems of both mutable and immutable type of structures…
m09
  • 7,490
  • 3
  • 31
  • 58
12
votes
1 answer

How to combine 2 Iterators in Scala?

a and b are values of Iterator[String] type. I need c to include all the elements of a and b. Surprisingly I can't figure out how to achieve this. May you happen to know?
Ivan
  • 63,011
  • 101
  • 250
  • 382
12
votes
3 answers

consume items from a scala Iterator

I'm confused about behavior of method take in trait Iterator. It seems that it doesn't consume items. Here is an example: scala> Iterator(1,2,3) res0: Iterator[Int] = non-empty iterator scala> res0 take 2 toArray res1: Array[Int] = Array(1,…
jglatre
  • 911
  • 1
  • 12
  • 15
12
votes
4 answers

scala turning an Iterator[Option[T]] into an Iterator[T]

I have an Iterator[Option[T]] and I want to get an Iterator[T] for those Options where T isDefined. There must be a better way than this: it filter { _ isDefined} map { _ get } I would have thought that it was possible in one construct... Anybody…
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
12
votes
2 answers

What's the difference between LazyList and Stream in Scala?

I noticed that Stream is deprecated in Scala 2.13 and they suggest using LazyList. They also say "Use LazyList (which is fully lazy) instead of Stream (which has a lazy tail only)". What does it exactly mean ? Why did they deprecate Stream ?
Michael
  • 41,026
  • 70
  • 193
  • 341