Last active
May 23, 2017 02:48
-
-
Save Hyperparticle/2a1b7ad7a132efa93c16c780c62ab3b7 to your computer and use it in GitHub Desktop.
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
// This file provides useful Kotlin tricks for common tasks | |
// that would be otherwise tedious to do in Java | |
/** | |
* Read from stdin line by line, halting when EOF is reached. | |
* Super useful for building a simple REPL or parsing a text file. | |
*/ | |
fun readLineByLine() { | |
System.`in`.reader().forEachLine { line -> | |
// Do your stuff here | |
println(line) | |
} | |
} | |
/** | |
* Configure an object's properties using Any.apply() | |
*/ | |
fun configureObjectProperties() { | |
val myObj = SomeObj().apply { | |
myObjProperty0 = value0 // Equivalent to: myObj.myObjProperty0 = value0 | |
myObjProperty1 = value1 | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment