Last active
December 20, 2015 05:38
-
-
Save egobrain/6079357 to your computer and use it in GitHub Desktop.
Call only last defined function wrapper (Coffee)
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
CallOnceConstructor = -> | |
cache = {} | |
(f) -> | |
cache.f_link?.f = null | |
f_link = f: f | |
cache.f_link = f_link | |
-> f_link.f?.apply null, arguments | |
# example | |
# call_last = CallOnceConstructor() | |
# f1 = call_last(...) | |
# f2 = call_last(...) | |
# f3 = call_last(...) | |
# only f3 will be performed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment