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
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() | |
} |
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 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()) | |
} |
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
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 { |