Created
January 11, 2018 14:02
-
-
Save xxKRASHxx/f3f61434155ed03ad1fb2365bb9b0075 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 weakify<Value: AnyObject, Arguments, Result>( | |
_ function: @escaping (Value) -> (Arguments) -> Result, | |
object: Value, | |
default value: Result) | |
-> (Arguments) -> Result { | |
return { [weak object] arguments in | |
object.map { function($0)(arguments) } ?? value | |
} | |
} | |
public func weakify<Value: AnyObject, Arguments>( | |
_ function: @escaping (Value) -> (Arguments) -> Void, | |
object: Value) | |
-> (Arguments) -> Void { | |
return weakify(function, object: object, default: ()) | |
} | |
public func weakify<Value: AnyObject>( | |
_ function: @escaping (Value) -> () -> Void, | |
object: Value) | |
-> () -> Void { | |
return { [weak object] in | |
object.map { function($0)() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment