Created
August 5, 2014 11:59
-
-
Save seoh/e0a1496568bf448e22d2 to your computer and use it in GitHub Desktop.
withExtendedLifetime
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
/** | |
/// f가 리턴하기 전에 `x`가 사라지지 않았을 때만 `f(x)`를 평가하고 결과를 반환한다. | |
func withExtendedLifetime<T, Result>(x: T, f: (T) -> Result) -> Result | |
func withExtendedLifetime<T, Result>(x: T, f: () -> Result) -> Result | |
**/ | |
func getClosure() -> ()->() { | |
var p = "yes" | |
func expired() { | |
println("is it alive?") | |
withExtendedLifetime(p) { | |
(s:String) in println(s) | |
} | |
} | |
return expired | |
} | |
var closure = getClosure() | |
closure() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wtf