Skip to content

User defined effects for Kotlin multiplatform

License

Notifications You must be signed in to change notification settings

ilaborie/Effekts

 
 

Repository files navigation

Effekts

User defined effects for Kotlin multiplatform

Example

User defined effects

sealed class IOConsole<T> : Effect<T>() {
    data class printString(val text: String) : IOConsole<Unit>()
    class readString : IOConsole<String>()
}

DSL for effects handling

handle<Unit, IOConsole<*>> {
    val name: String = perform(readString())
    perform(printString("Hello $name"))
} with {
    when (it) {
        is printString -> {
            println(it.text)
            it.resume(Unit)
        }
        is readString -> {            
            it.resume("World")
        }
    }
}

About

User defined effects for Kotlin multiplatform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%