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
// File: Echo.kt | |
package example | |
fun main(args: Array<String>) { | |
println(args.joinToString(" ")) | |
} |
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
$ kotlin example.EchoKt Testing 1 2 3... | |
Testing 1 2 3... |
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 words = arrayOf( | |
"out", "of", "mind", | |
"back", "in", "five") | |
println(words[2]) // prints "mind" |
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 main() = println("Greetings Earth!") |
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
// Scramble from files/stdin to stdout | |
fun main(args: Array<String>) { | |
// Collect readers from args/stdin | |
val readers = | |
if (args.isNotEmpty()) | |
args.map { File(it).reader() } | |
else | |
// in: quoted because reserved |
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
wscrambler.scrambleWords("Hey there!") |
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
package wscrambler | |
object WordScrambler { | |
// Regex compiled only once: | |
// at object initialization. | |
// Inaccessible to others, | |
// even in the same package. | |
private val WORD_REGEX = | |
"""\p{IsLatin}(\p{IsLatin})\1*(?!\1)\p{IsLatin}\p{IsLatin}+""" |
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
// Nullable constructor arg w/default | |
class Numberer(pattern: String? = null) { | |
companion object { | |
// Public constant | |
const val DEF_PATTERN = "000,000" | |
} | |
// Private field w/fallback value (?:) |
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
package wscrambler | |
object WordScrambler { | |
private val WORD_REGEX = | |
"""\p{IsLatin}(\p{IsLatin})\1*(?!\1)\p{IsLatin}\p{IsLatin}+""".toRegex() | |
@JvmStatic // JVM static method | |
// CLI FQN: wscrambler.Scrambler | |
fun main(args: Array<String>) { |
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
do { | |
// ... shuffling stuff... | |
// Ensure shuffling took place! | |
} while (range.all { | |
result[it] == text[it] }) |