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 dev.akif.periodik | |
import dev.akif.periodik | |
import kotlinx.coroutines.* | |
import org.junit.jupiter.api.Timeout | |
import org.slf4j.Logger | |
import org.slf4j.LoggerFactory | |
import kotlin.random.Random | |
import kotlin.reflect.KProperty | |
import kotlin.test.Test |
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
case class BarDBConfig(connectionString: String) extends DBConfig | |
object BarDBConfig extends DBConfig.Builder[BarDBConfig]("bar") |
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 scala.annotation.tailrec | |
sealed trait Stack[A]: | |
def push(a: A): Stack[A] | |
def pop(): (Option[A], Stack[A]) | |
def size: Int | |
def reverse(): Stack[A] = | |
@tailrec def go(s1: Stack[A], s2: Stack[A]): Stack[A] = | |
s1.pop() match |
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 com.fasterxml.jackson.databind.JsonNode | |
object JsonExtensions { | |
fun JsonNode.objectAt(key: String): JsonNode? = this.takeIf { it.isObject }?.get(key)?.takeIf { it.isObject } | |
fun JsonNode.arrayAt(key: String): JsonNode? = this.takeIf { it.isObject }?.get(key)?.takeIf { it.isArray } | |
fun JsonNode.booleanAt(key: String): Boolean? = this.takeIf { it.isObject && it.has(key) }?.get(key)?.takeIf { it.isBoolean }?.asBoolean() | |
fun JsonNode.intAt(key: String): Int? = this.takeIf { it.isObject && it.has(key) }?.get(key)?.takeIf { it.isIntegralNumber }?.asInt() | |
fun JsonNode.longAt(key: String): Long? = this.takeIf { it.isObject && it.has(key) }?.get(key)?.takeIf { it.isIntegralNumber }?.asLong() | |
fun JsonNode.doubleAt(key: String): Double? = this.takeIf { it.isObject && it.has(key) }?.get(key)?.takeIf { it.isFloatingPointNumber }?.asDouble() |
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.math.BigDecimal | |
sealed class Json { | |
companion object { | |
fun `null`(): JNull = JNull | |
fun arr(vararg values: Json): JArray = JArray(*values) | |
fun obj(vararg pairs: Pair<String, Json>): JObject = JObject(*pairs) |
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
sealed class Option<out A>(open val value: A?) { | |
fun <B> fold(ifNone: () -> B, ifSome: (A) -> B): B = | |
when (this) { | |
is None -> ifNone() | |
is Some -> ifSome(this.value) | |
} | |
// This doesn't compile because `out` type A is in `in` position | |
fun getOrElseThatWontWork(default: () -> A): A = | |
when (this) { |
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 scala.util.Try | |
implicit class KotlinLikeExtensions[A](a: => A) { | |
/** | |
* Produce a new value using current value | |
*/ | |
def let[B](f: A => B): B = f(a) | |
/** | |
* Do something with current value and produce nothing |
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
// Behavior of talking | |
interface Talks { | |
void talk(String what); | |
} | |
// Behavior of making sound | |
interface MakesSound { | |
void makeSound(String what); | |
} |
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
git filter-branch -f --prune-empty --tree-filter ' | |
find . \ | |
-name .git -prune -o \ | |
-exec sh -c "file {} | grep -q text" \; \ | |
-exec sed -i "" \ | |
-e "s/X/Y/g" \ | |
-e "s/com.x.y/com.github.makiftutuncu.trump/g" \ | |
-e "s/x/y/g" \ | |
{} \; \ | |
&& mkdir -p src/main/scala/com/github/makiftutuncu/trump && mkdir -p src/test/scala/com/github/makiftutuncu/trump && tree src && mv src/main/scala/com/x/y/* src/main/scala/com/github/makiftutuncu/trump && mv src/test/scala/com/x/y/* src/test/scala/com/github/makiftutuncu/trump && tree src |
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.util.Optional; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
import java.util.function.Supplier; | |
public abstract class Either<L, R> { | |
public static final class Left<L, R> extends Either<L, R> { | |
public Left(L left) { | |
super(left, null); | |
} |
NewerOlder