Created
September 8, 2010 05:04
-
-
Save yuroyoro/569660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trait Memoized[T,R] { | |
| import scala.collection.mutable._ | |
| private[this] val cache = new HashMap[T,R] | |
| def cacheOrApply( t:T )( f: => R ):R = cache get(t) getOrElse{ | |
| val rv = f | |
| cache += t -> rv | |
| rv | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment