Skip to content

Instantly share code, notes, and snippets.

@Hyperparticle
Last active May 23, 2017 02:48
Show Gist options
  • Save Hyperparticle/2a1b7ad7a132efa93c16c780c62ab3b7 to your computer and use it in GitHub Desktop.
Save Hyperparticle/2a1b7ad7a132efa93c16c780c62ab3b7 to your computer and use it in GitHub Desktop.
// 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