All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalatra.util.MapWithIndifferentAccess.scala Maven / Gradle / Ivy

The newest version!
package org.scalatra.util

import scala.collection.Map

/**
 * Inspired by Rails' MapWithIndifferentAccess, allows the substitution of symbols for strings as map keys.  Note
 * that the map is still keyed with strings; symbols are stored in permgen, so symbol keys maps should not be used
 * for maps with arbitrary keys.  There is no performance gain using symbols.  It is here to make our Rubyists feel
 * more at home.
 */
trait MapWithIndifferentAccess[+B] extends Map[String, B] {
  def get(key: Symbol): Option[B] = get(key.name)
  def getOrElse[B1 >: B](key: Symbol, default: => B1): B1 = getOrElse(key.name, default)
  def apply(key: Symbol): B = apply(key.name)
  //def apply(keys: Symbol*): Seq[V] = keys map get _
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy