// Created on savesnippets.com ยท https://savesnippets.com/oRGuVlB4isVy3s // String extension properties val String.wordCount: Int get() = trim().split("\\s+".toRegex()).filter { it.isNotEmpty() }.size val List.lastIndex: Int get() = size - 1 // Pair where both halves are the same: doubled val T.asPair: Pair get() = this to this fun main() { println("hello world foo bar".wordCount) // 4 val xs = listOf("a", "b", "c", "d") println(xs.lastIndex) // 3 (built-in too, but instructive) println(42.asPair) // (42, 42) println("hi".asPair) // (hi, hi) }