This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I want to parameterize a container F as well as the contents A | |
Mappable<F<A>> | |
// but type parameters can't have type parameters in Kotlin :-( | |
// Instead of a type parameter of a type parameter, | |
// what if I just use two type parameters? | |
Mappable<Kind<F,A>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun SingleK.Companion.runtime(ctx: RuntimeContext) = object : Runtime<ForSingleK>( | |
SingleK.concurrent( | |
object : Dispatchers<ForSingleK> { | |
override fun default(): CoroutineContext = Schedulers.computation().asCoroutineContext() | |
override fun io(): CoroutineContext = Schedulers.io().asCoroutineContext() | |
} | |
), ctx | |
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun IO.Companion.runtime(ctx: RuntimeContext) = object : Runtime<ForIO>( | |
IO.concurrent(), ctx | |
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <F> Runtime<F>.loadNews(): Kind<F, List<NewsItem>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@higherkind | |
sealed class Option<out A> : OptionOf<A> { | |
// snip | |
} | |
// the annotation processor will emit the following code for the witness: | |
// class ForOption private constructor() { companion object } | |
// typealias OptionOf<A> = arrow.Kind<ForOption, A> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extension | |
interface OptionMappable : Mappable<ForOption> { | |
override fun <A, B> OptionOf<A>.map(f: (A) -> B): Option<B> = | |
fix().map(f) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Mappable<F> { | |
fun <A, B> Kind<F, A>.map(f: (A) -> B): Kind<F, B> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ForOption private constructor() { companion object } | |
typealias OptionOf<A> = arrow.Kind<ForOption, A> | |
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE") | |
inline fun <A> OptionOf<A>.fix(): Option<A> = | |
this as Option<A> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val a: Kind<ForOption, Int> = Option(1) | |
val fixedA: Option<Int> = a.fix() |