} object IntMonoid: Monoid<Int> { override val unit: Int = 0 override fun Int.combine(that: Int): Int = this + that } context(Monoid<T>) fun <T> List<T>.sum(): T = fold(unit) { acc, e -> acc.combine(e) } with(IntMonoid) { val sum = listOf(1, 2, 3).sum() println(sum) // 6 } 参考 https://github.com/Kotlin/KEEP/blob/context-receivers/proposals/context-receivers.md#use-cases