Skip to content

Instantly share code, notes, and snippets.

View AlexeySoshin's full-sized avatar

Alexey Soshin AlexeySoshin

View GitHub Profile
@elizarov
elizarov / AspectOperators.kt
Last active September 8, 2022 07:56
Aspect operators
// Aspect interface for combinator
interface Aspect {
operator fun <R> invoke(block: () -> R): R
}
// Aspect combinator
operator fun Aspect.plus(other: Aspect) = object : Aspect {
override fun <R> invoke(block: () -> R): R =
this@plus {
other {
@norswap
norswap / ObjectAlgebra.kt
Created January 18, 2016 16:30
Object Algebras in Kotlin
// Basic setup
interface Exp
data class Lit(val x: Int): Exp
data class Add(val x: Exp, val y: Exp): Exp
interface IntAlg<A>
{
fun lit(x: Int): A
fun add(x: A, y: A): A