Skip to content

Instantly share code, notes, and snippets.

@subinkrishna
Last active February 16, 2018 17:17
Show Gist options
  • Save subinkrishna/7ecde4311f0a40b6ff9dafb60f2710e2 to your computer and use it in GitHub Desktop.
Save subinkrishna/7ecde4311f0a40b6ff9dafb60f2710e2 to your computer and use it in GitHub Desktop.
class MyClass {
fun test() {
val str: String = "..."
val result = str.xxx {
print(this) // Receiver
print(it) // Argument
42 // Block return value
}
}
}
╔══════════╦═════════════════╦═══════════════╦═══════════════╗
║ Function ║ Receiver (this) ║ Argument (it) ║ Result ║
╠══════════╬═════════════════╬═══════════════╬═══════════════╣
║ let ║ this@MyClass ║ String("...") ║ Int(42) ║
║ run ║ String("...") ║ N\A ║ Int(42) ║
║ run* ║ this@MyClass ║ N\A ║ Int(42) ║
║ with* ║ String("...") ║ N\A ║ Int(42) ║
║ apply ║ String("...") ║ N\A ║ String("...") ║
║ also ║ this@MyClass ║ String("...") ║ String("...") ║
╚══════════╩═════════════════╩═══════════════╩═══════════════╝
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment