Skip to content

Instantly share code, notes, and snippets.

@hmhmsh
Created May 31, 2017 08:03
Show Gist options
  • Save hmhmsh/016582e6f9d88c9ec309035b1f9d9936 to your computer and use it in GitHub Desktop.
Save hmhmsh/016582e6f9d88c9ec309035b1f9d9936 to your computer and use it in GitHub Desktop.
Extension of Swift like Kotlin
protocol Kotlin {}
extension Kotlin {
func lets<R>(_ closure: (Self) -> R) -> R {
return closure(self)
}
func apply(closure: (Self) -> Void) -> Self {
closure(self)
return self
}
}
extension Int: Kotlin {}
extension NSObject: Kotlin {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment