|
|
|
|
|
by kasey_junk
4501 days ago
|
|
An example I use a lot because it is terse: From MapLike.scala
def apply(key: A): B = get(key) match { case None => default(key) case Some(value) => value } From HashMap.scala
def get(key: A): Option[B] = { val e = findEntry(key) if (e eq null) None else Some(e.value) } That is to say that the default behaviour of a Scala hash map is to create a new object for every access (notice I say access, not for every insert) even when I ask it to pretty please give me the one that doesn't have the null safe Option code involved. |
|