From 1e88594f358d08b5e9b22ba87280003a581359e4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 7 Dec 2009 17:31:49 +0000 Subject: new doc comment generation, including some new ... new doc comment generation, including some new style doc comments in collection classes. --- src/library/scala/collection/mutable/MapLike.scala | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/library/scala/collection/mutable/MapLike.scala') diff --git a/src/library/scala/collection/mutable/MapLike.scala b/src/library/scala/collection/mutable/MapLike.scala index d03858a68f..92f1b5bba6 100644 --- a/src/library/scala/collection/mutable/MapLike.scala +++ b/src/library/scala/collection/mutable/MapLike.scala @@ -103,6 +103,15 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]] */ override def updated[B1 >: B](key: A, value: B1): mutable.Map[A, B1] = this + ((key, value)) + /** If given key is already in this map, returns associated value + * Otherwise, computes value from given expression `op`, stores with key + * in map and returns that value. + */ + def cached(key: A, op: => B) = get(key) match { + case Some(v) => v + case None => val v = op; update(key, v); v + } + /** Add a new key/value mapping and return the map itself. * * @param kv the key/value mapping to be added -- cgit v1.2.3