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
/** | |
* Calls the specified function [block] and returns its result. | |
*/ | |
public inline fun <R> run(block: () -> R): R { | |
return block() | |
} | |
/** | |
* Calls the specified function [block] with `this` value as its receiver and returns its result. | |
*/ |
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
val window = ApplicationWindow() | |
// 'this' is the global scope | |
window.apply { | |
// 'this' scopes to 'window' | |
this.content.loadImage("whatever.png") | |
// 'this' scopes to 'window' | |
this.header.buttons.run { | |
// 'this' scopes to 'window.header.buttons' | |
add("X") |
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
val window = ApplicationWindow().apply { | |
content.loadImage("whatever.png") | |
header.buttons.run { | |
add("X") | |
add("_") | |
add("□") | |
} | |
onWindowClose = { |
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
val window = ApplicationWindow() | |
window.content.loadImage("whatever.png") | |
window.header.buttons.add("X") | |
window.header.buttons.add("_") | |
window.header.buttons.add("□") | |
window.onWindowClose = { | |
println("Bye bye") |
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
/** | |
* Calls the specified function [block] with `this` value as its receiver and returns `this` value. | |
*/ | |
public inline fun <T> T.apply(block: T.() -> Unit): T { | |
block() | |
return this | |
} |
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
// Standard | |
val alice = Person("Alice", 20, "Amsterdam") | |
println(alice) | |
alice.moveTo("Detroit") | |
alice.incrementAge() | |
alice.alias = "Ally" | |
println(alice) | |
// Using let | |
Person("Bob", 21, "Bruges").let { it -> |
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
/** | |
* Calls the specified function [block] with `this` value as its argument and returns its result. | |
*/ | |
public inline fun <T, R> T.let(block: (T) -> R): R { | |
return block(this) | |
} |
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
<?xml version='1.0' encoding='utf-8' standalone='yes' ?> | |
<map> | |
<string name="name">Andrea</string> | |
<int name="id" value="1" /> | |
</map> |
NewerOlder