Skip to content

Instantly share code, notes, and snippets.


Preston Garno prestongarno

View GitHub Profile
prestongarno / puzzler.kt
Last active May 19, 2018
What is the output of this program?
View puzzler.kt
import kotlin.reflect.KProperty
class ResponsibleDelegate<out T>(initializer: () -> T?) {
private val value by lazy(initializer)
operator fun getValue(thisRef: Any?, property: KProperty<*>): T =
value ?: throw NullPointerException()
View destructuregex.kt
fun parsePhoneNumber(text: String): PhoneNumber {
val destructuredRegex = "([0-9]{3})-([0-9]{3})-([0-9]{4})".toRegex()
return destructuredRegex.matchEntire(text)
?.let { (areaCode, prefix, lineNumber) ->
PhoneNumber(areaCode.toInt(), prefix.toInt(), lineNumber.toInt())
import java.nio.file.*;
import java.nio.file.spi.FileSystemProvider;
import java.util.*;
import java.util.function.Function;
import javax.swing.*;
public class CustomFileChooser {