Skip to content

Instantly share code, notes, and snippets.

View roschlau's full-sized avatar

Robin roschlau

  • Echometer GmbH
  • Münster, Germany
  • X @lushorac
View GitHub Profile
@roschlau
roschlau / event.kt
Last active July 7, 2017 13:32 — forked from orangy/event.kt
C#-style events in Kotlin
class Event<T> {
private val handlers = arrayListOf<(T) -> Unit>()
operator fun plusAssign(handler: (T) -> Unit) { handlers.add(handler) }
operator fun invoke(value: T) { for (handler in handlers) handler(value) }
}
val e = Event<String>() // define event
fun main(args : Array<String>) {
e += { println(it) } // subscribe