Learning Kotlin and Swift
Making Kotlin Scope Functions in Swift
Explore the different between Kotlin and Swift
5 min readMar 17, 2020
If you have used Kotlin before, very likely you have used one of the Standard Scope function e.g. let, apply, with, run, etc. They are so handy. Check out the article below, if you haven’t heard of it.
However, when switch over to Swift, they are not readily available. So I’m attempting to make my own version of it (the implemented codes are at the bottom of this blog)
What’s required to make scope function?
In order to do that, let’s look at what a Scope function needed. I pick one that has all the needing attributes
// Kotlin
public inline fun <T, R> T.run(block: T.() -> R): R1. It prefers to inline the function
// Kotlin
public inline fun <T, R> T.run(block: T.() -> R): R