i'm trying use concatenation of string litterals value in map[int, string]
definition:
scala> val m: map[int, string] = map(1 -> "a" + "b")
but following error sbt console
<console>:7: error: type mismatch; found : string required: (int, string) val m: map[int, string] = map(1 -> "a" + "b")
the reason want such thing because want define maps id code so:
map(1 -> s"""select year, count(*) from""" + s""" (select id, year(pb_date) year publications) res1""" + s"""group year;""")
without having define string each of code snippets present map right value.
is there way achieve this?
you missing parentheses:
scala> val m: map[int, string] = map(1 -> ("a" + "b")) m: map[int,string] = map(1 -> ab)
the reason why getting error because ->
takes precedence on +
, meaning (1 -> "a") + b
, can see below:
scala> 1 -> "a" + "b" res4: string = (1,a)b