Forked from jeremytregunna/gist:d9c7572e2dd50c584e7a
Last active
August 29, 2015 14:10
-
-
Save beelsebob/92b3d3c393fb5222a59f to your computer and use it in GitHub Desktop.
This file contains 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
public func memoize<T: Hashable, U>(f: (T) -> U) -> (T) -> U { | |
var memo : [T : U] = [:] | |
return { x in | |
if let q = memo[x] { | |
return q | |
} | |
let r = f(x) | |
memo[x] = r | |
return r | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment