0
votes
2answers
36 views

Scala: Remove none elements from map and flatten

I have a map: Map("key1" -> Some("value1"), "key2" -> None, "key3" -> Some("value3")) I want to remove all None elements an flatten the map. Which is the easiest way to accomplish that? I ...
1
vote
4answers
190 views

How do I make this tail recursive?

In my Scala app, I have a function that calls a function which returns a result of type Future[T]. I need to pass the mapped result in my recursive function call. I want this to be tail recursive, ...
2
votes
1answer
65 views

persistent data structure (in Scala) that supports fast lookup AND insertion order?

When I work with maps, I tend to prefer ones whose elements can be iterated through in the same order they were inserted. It makes them feel more deterministic and easier to test. For this reason and ...
6
votes
2answers
127 views

why both transform and map methods in scala?

I'm having trouble understanding the difference between / reason for, for example, immutable.Map.transform and immutable.Map.map. It looks like transform won't change the key, but that just seems ...
1
vote
1answer
131 views

Can someone explain me the line in between ** ? I don't understand how the map is working

def combinations(occurrences: Occurrences): List[Occurrences] = occurrences match { case List() => List(List()) case occ :: occs => for { **occSub <- (0 to ...
1
vote
2answers
56 views

Why does Map addition of duplicates only take the last key's value

Per this question: Best way to merge two maps and sum the values of same key? I would need to use scalaz to get what I want, however I am curious if anybody knew why the below does not work as I ...
0
votes
1answer
31 views

Scala - diverging implicit expansion when using toMap

I have the following definition of an enum: object GraphType extends Enumeration { type Type = Value val MESSAGE, REQUEST, ERRORS = Value } Now I am trying to map each of the type to the ...
0
votes
3answers
89 views

Extract second tuple element in list of tuples

I have a Map where each value is a list of Tuples such as: List(('a',1), ('b', 4), ('c', 3)....) what is the most scala-thonic way to change each value is still a LIst but is only the second ...
1
vote
2answers
73 views

Convert map to a sorted list

I have a map... Map(a -> List(a, a), b -> List(b, b), l -> List(l, l)) I can convert to a List List((a,2), (l,2), (b,2)) By simply doing myMap.toList(); But I'd like to convert to a ...
0
votes
1answer
42 views

Convert map to get size of lists in each element

I have a Map of element where each element has a List as its value e.g. Map(a -> List(a, a), b -> List(b, b), l -> List(l, l, l), h -> List(h)) I want to convert this so that each value ...
0
votes
2answers
94 views

Missing paramenter when I use map (Scala)

I'm having an irritating error which I can't find any explanation for. I have this code here below: Async{ WS.url(url).get().map{ response => //response here is giving me the error. ...
0
votes
2answers
51 views

How to append to a LinkedList inside a HashMap?

Given is the following construct import scala.collection.mutable.HashMap import scala.collection.mutable.LinkedList private var log = new HashMap[String, LinkedList[String]] How do I append to the ...
0
votes
2answers
117 views

For comprehension with Map lookup - is there a better way?

Consider the following val myMap: Map[String, List[Int]] = Map("a" -> List(1,2,3), "b" -> List(4,5,6), "d" ...
3
votes
1answer
90 views

Zip two HashMaps(or dictionaries)

What would be a functional way to zip two dictionaries in Scala? map1 = new HashMap("A"->1,"B"->2) map2 = new HashMap("B"->22,"D"->4) // B is the only common key zipper(map1,map2) ...
2
votes
3answers
92 views

vector with 10^7 elements in scala

i was testing ruby, python and scala to see which one has better support for huge arrays. Ruby (each) -> 84 MB, 2s # a = [];(0...1e7).each{|i| a[i]=i} Ruby (expand) -> 254 MB, 60s #a = ...

1 2 3 4 5 14
15 30 50 per page