Created
November 26, 2013 00:50
-
-
Save robotlolita/7651623 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
memoised-fork = (f, future) -> | |
pending = [] | |
fold = (g, h) -> | |
fold := (g, h) -> pending.push rejected: g, resolved: h | |
f do | |
* (a) -> do | |
future.is-pending := false | |
future.is-rejected := true | |
future.value := a | |
fold := (ff, _) -> ff a | |
invoke-pending \rejected, a | |
g a | |
* (b) -> do | |
future.is-pending := false | |
future.is-resolved := true | |
future.value := a | |
fold := (_, ff) -> ff b | |
invoke-pending \resolved, b | |
h b | |
return (g, h) -> fold g, h | |
function invoke-pending(kind, value) | |
for x in pending => x[kind] value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment