Scala - How to return a Map value by function? -


why below function not work in scala?

def getupdatedmap(keywords: string, m: map[string, string]) : map[string, string] = {   m += (keywords -> "abcde") } 

compilation error: value += not member of map[string, string]

i'm quite new in scala, thing have forget define or missing? thanks.

you confusing immutable map , mutable map.

// import mutable map mutablemap import scala.collection.mutable.{map => mutablemap}  val mmap = mutablemap("a" -> 1) mmap += "b" -> 2 // mutates original map // mmap = map(b -> 2, -> 1)  // use immutable map val imap = map("c" -> 3) val updatedimap = imap.updated("d", 4) // returns new updated immutable map // imap = map("c" -> 3) // updateimap = map(c -> 3, d -> 4) 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -