Getting values from a map

As I slowly progress in Scala I was trying to get values from a map and if not found return some kind of default value. Being still a java-head, I tried it initially to do it like the following:

var templates:Map[String, String] = Map()

... some code to fill the templates...

// wont compile
def locateTemplate(name: String) : String = {
    if (templates.get(name) == null) {
        templates.get(name)
    }
    else {
        // by default return the name itself
        name
    }
}

Continue reading “Getting values from a map”