Skip to content

Instantly share code, notes, and snippets.

@AlexeySoshin
Last active July 7, 2020 11:59
Show Gist options
  • Save AlexeySoshin/fc7311a167d24d54c5777f7f2ab79dd9 to your computer and use it in GitHub Desktop.
Save AlexeySoshin/fc7311a167d24d54c5777f7f2ab79dd9 to your computer and use it in GitHub Desktop.
sealed class KIO<out A> {
fun <B> flatMap(f: (A) -> KIO<B>): KIO<B> {
return FlatMap(this, f)
}
fun <B> map(f: (A) -> B): KIO<B> {
return flatMap { a ->
Effect {
f(a)
}
}
}
}
data class Effect<out A>(val f: () -> A) : KIO<A>()
data class FlatMap<A, out B>(
val input: KIO<A>,
val f: (A) -> KIO<B>
) : KIO<B>()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment