Skip to content

Instantly share code, notes, and snippets.

@AndreyPanov
Created May 9, 2017 14:21
Show Gist options
  • Save AndreyPanov/5d673ef80a88a21348f77d04013ba556 to your computer and use it in GitHub Desktop.
Save AndreyPanov/5d673ef80a88a21348f77d04013ba556 to your computer and use it in GitHub Desktop.
protocol Chainable: class {
var before: (()->())? { get set }
func before(_ callback: @escaping ()->()) -> Self
func invoke()
}
extension Chainable {
@discardableResult
func before(_ callback: @escaping ()->()) -> Self {
before = callback
return self
}
func invoke() {
before?()
before = nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment