Christian Maus
12/29/2019, 11:20 AMfun <IP, R> (() -> IP).then(f: (IP) -> R): () -> R = { f(this()) }
sealed class Option<out T>
data class Some<T>(val value: T) : Option<T>()
object None : Option<Nothing>()
fun maybeNull(): String? = "abcd"
fun <T> toOption(value: T?) = if (value != null) {
Some(value)
} else {
None
}
fun toStringOption(value: String?) = value?.let { Some(value) } ?: None
//should be inferred to () -> Option<String>, but is inferred to () -> Option<String?>
val does_not_work: () -> Option<String> = ::maybeNull.then(::toOption)
//type is correct if no generic type is used
val works: () -> Option<String> = ::maybeNull.then(::toStringOption)
dmitriy.novozhilov
12/29/2019, 11:36 AM-Xnew-inference
compiler flagraulraja
12/29/2019, 11:37 AM