Skip to content

Instantly share code, notes, and snippets.

View PhBastiani's full-sized avatar

Philippe Bastiani PhBastiani

View GitHub Profile
@raulraja
raulraja / TwitterHandle.kt
Created February 20, 2020 12:16
Type Refinements with Type Proofs in Kotlin
/* Coming up ~ April 2020 */
package test
import arrow.*
inline class TwitterHandle(val handle: String) {
companion object : Refined<String> {
override val validate: String.() -> Map<String, Boolean> = {
mapOf(
"Should start with '@'" to startsWith("@"),
sealed class Expression<A> {
abstract val value: A
}
data class Num(override val value: Int) : Expression<Int>()
data class Bool(override val value: Boolean) : Expression<Boolean>()
data class Add(val a: Expression<Int>, val b: Expression<Int>) : Expression<Int>() {
override val value: Int get() = a.value + b.value
}
data class Equals<A>(val first: Expression<A>, val second: Expression<A>) : Expression<Boolean>() {
override val value: Boolean get() = first.value == second.value
@elizarov
elizarov / Delimited.kt
Last active October 23, 2023 20:19
Delimited Continuations shift/reset in Kotlin
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
/**
* Implementation for Delimited Continuations `shift`/`reset` primitives via Kotlin Coroutines.
* See [https://en.wikipedia.org/wiki/Delimited_continuation].
*
* The following LISP code:
*
* ```