Skip to content

Instantly share code, notes, and snippets.

View prestongarno's full-sized avatar

Preston Garno prestongarno

View GitHub Profile
@prestongarno
prestongarno / puzzler.kt
Last active May 19, 2018 17:57
What is the output of this program?
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()
}
fun parsePhoneNumber(text: String): PhoneNumber {
val destructuredRegex = "([0-9]{3})-([0-9]{3})-([0-9]{4})".toRegex()
return destructuredRegex.matchEntire(text)
?.destructured
?.let { (areaCode, prefix, lineNumber) ->
PhoneNumber(areaCode.toInt(), prefix.toInt(), lineNumber.toInt())
}
import java.io.*;
import java.nio.file.*;
import java.nio.file.spi.FileSystemProvider;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.swing.*;
public class CustomFileChooser {