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
/** | |
* 6/15/2020 | |
* An example to show local final | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
class LocalConstant { | |
val CONSTANT = "allows all data types" | |
} |
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
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
public inline fun <T> T.also(block: (T) -> Unit): T { | |
/*...*/ | |
block(this) | |
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
public inline fun <T, R> T.run(block: T.() -> R): R { | |
/*...*/ | |
return block() | |
} |
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
fun doSomething(name: String) { | |
println("Name from the method doSomething is: $name") | |
} |
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
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
private fun getEvenOrNull(randomNumber: Int): Int? = | |
if (randomNumber.rem(2) == 0) randomNumber else null |
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
public inline fun <T, R> with(receiver: T, block: T.() -> R): R { | |
/*…*/ | |
return receiver.block() | |
} |
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
/** | |
* 5/8/2020 | |
* A function type without any parameter | |
* <p> | |
* if the higher order function has only one function type parameter and the function type has no parameter, | |
* We can simply write our business logic between curly parentheses right after the name of the function. | |
* </p> | |
* @author srdpatel | |
* @since 1.0 | |
*/ |
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
//region A function type that has no parameter | |
private fun doSomethingY(ft: () -> String) { | |
/*...*/ | |
} | |
//endregion |