Skip to content

Instantly share code, notes, and snippets.

@seoh
Created August 5, 2014 11:59
Show Gist options
  • Save seoh/e0a1496568bf448e22d2 to your computer and use it in GitHub Desktop.
Save seoh/e0a1496568bf448e22d2 to your computer and use it in GitHub Desktop.
withExtendedLifetime
/**
/// 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()
@seoh
Copy link
Author

seoh commented Aug 5, 2014

wtf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment